【问题标题】:How to reject/close specific incoming number如何拒绝/关闭特定的来电号码
【发布时间】:2014-06-08 17:24:36
【问题描述】:

在我的应用程序中,我想阻止特定的传入号码。我用谷歌搜索,并关注Blocking Incoming call - Android。但是这段代码对我不起作用。我正在 android 2.3.5

上进行测试

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

ma​​nifest.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();

}

【问题讨论】:

  • 您的代表建议您已经存在足够长的时间来知道您的问题是不完整的,并且只是要求读者在不知道他们正在寻找什么问题的情况下查看您的代码(“它没有” t work”是不够的)被强烈反对。

标签: android phone-call


【解决方案1】:

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

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

对于创建.aidl文件New &gt; File并写入ITelephony.aidl

并按照步骤Blocking a call without user intervention in android with an example.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多