2

在我的应用程序中,我想阻止特定的来电号码。我用谷歌搜索,然后按照Blocking Incoming call - Android。但是这段代码对我不起作用。我正在android 2.3.5上测试

在这里我没有活动课。>> 第一类是扩展广播接收器。

清单.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();
            }
        }
    }

}
}

IT电话

public interface ITelephony {

    boolean endCall();

    void answerRingingCall();

    //void silenceRinger();

}
4

1 回答 1

1

最后解决问题,创建获取核心Telephony服务包名的IDL接口必须是com.android.internal.telephony

FileName : ITelephony.aidl // 首先我在这里创建ITelephony.java

对于创建.aidl文件New > File并写入ITelephony.aidl

并按照示例在 android 中阻止呼叫而无需用户干预的步骤进行操作。

于 2013-06-29T11:41:53.207 回答