Android Dual Sim拒绝来电

时间:2018-02-16 09:59:51

标签: android

请帮助我们的Android应用程序调用在应用程序中拒绝来电,代码适用于单SIM机器人,双SIM卡问题。

以下是我的代码:

广播接收器

@SuppressLint("WrongConstant")
public void onReceive(Context context, Intent intent) {

    mainPrefs = context.getSharedPreferences("mainPrefs", MODE_WORLD_READABLE);
    String rejectMode = mainPrefs.getString("mode", "not retrieved");

    if (rejectMode.equals("enable")) {

        if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

                RejectcallHandler mDbAdapter = new RejectcallHandler(context);
                mDbAdapter.open();
                Cursor cursor = mDbAdapter.fetchAllRejectList();
                if (cursor.moveToFirst()) {
                    while (!cursor.isAfterLast()) {
                        String rejectNumber = cursor.getString(cursor.getColumnIndex(RejectcallHandler.COLUMN_RCNUMBER));
                        if (incomingNumber.startsWith(rejectNumber)) {
                            rejectCall(context, intent);
                            //showNotification(context, incomingNumber);

                            String value = mainPrefs.getString("show_notification", "notify_enable");

                            if (value.equals("notify_enable")) {
                                showNotification(context, incomingNumber);
                            }
                        }
                        cursor.moveToNext();
                    }
                }
                cursor.close();
                mDbAdapter.close();
            }
        }
    } else if (rejectMode.equals("disable")) {

    }
}

这是我的android清单权限

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

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

0 个答案:

没有答案