How to reject/close specific incoming number

别说谁变了你拦得住时间么 提交于 2019-12-20 03:46:13

问题


In my application I want to block the specific incoming number.I do google,and following Blocking Incoming call - Android. But this code is not working for me.I am testing on android 2.3.5

Here I have no activity class. >> First class is extends BroadcastReceiver.

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blocknumber"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />  
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> 
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <receiver android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>
</application>

MainActivity.class

public class MainActivity extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
    String blockedNumbers[] = { "xxxxxxxxxx", "xxxxxxxxxx" };
    Bundle b = intent.getExtras();
    /*
     * String incommingNumber = b
     * .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
     */
    String incommingNumber = b.getString("incoming_number");
    Log.e("Incomming number========>", incommingNumber);
    // String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

    for (int i = 0; i < blockedNumbers.length; i++) {
        Log.e("Incomming >>>>>>>>>>>>>========>", "" + i);
        if (incommingNumber.equalsIgnoreCase(blockedNumbers[i])) {
            TelephonyManager telephony = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            try {
                Class<?> c = Class.forName(telephony.getClass().getName());
                Method m = c.getDeclaredMethod("getITelephony");
                m.setAccessible(true);
                ITelephony telephonyService = (ITelephony) m
                        .invoke(telephony);
                // telephonyService.silenceRinger();
                telephonyService.endCall();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
}

ITelephony

public interface ITelephony {

    boolean endCall();

    void answerRingingCall();

    //void silenceRinger();

}

回答1:


Finally, solve the issue, Create IDL interface for getting core Telephony service package name must be com.android.internal.telephony

FileName : ITelephony.aidl // First Here I am createing ITelephony.java

For the create .aidl file New > File and write ITelephony.aidl

And follow the steps Blocking a call without user intervention in android with an example.



来源:https://stackoverflow.com/questions/17363534/how-to-reject-close-specific-incoming-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!