1

我从这里得到了禁用/启用广播接收器的逻辑。

@Override
    public void onCheckedChanged(CompoundButton v, boolean checked) {
        // TODO Auto-generated method stub

        if (v == disableBlock) {
            manageBlockSetting(checked);
        }
    }

private void manageBlockSetting(boolean disable) {
        Log.e(tag, "Disable : " + disable);
        int flag = disable ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
                : PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        ComponentName component = new ComponentName(SettingActivity.this, PhoneCallReceiver.class);

        getApplication().getPackageManager().setComponentEnabledSetting(component, flag, PackageManager.DONT_KILL_APP);
        editSharedPreferences(StoreConstantValue.SETTING_DISABLE_BLOCK, disable);
}

在 Manifest.xml 中

<receiver android:name="com.vsmart.unocaller.blockingservice.PhoneCallReceiver" 
            android:enabled="true" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

当我部署时android:enabled="false"

我可以启用它一次。但是当我想禁用时。没有任何反应,我无法禁用它。它仍然阻止来电。

我的设备是带有 Android 2.3.3 的三星 Galaxy S2

有什么帮助吗?谢谢

4

1 回答 1

1

您可以尝试从代码中注册/注销它,而不是在清单中声明接收者。例如

private class MyPhoneStateListener extends PhoneStateListener {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        super.onCallStateChanged(state, incomingNumber);

    }
}


private MyPhoneStateListener phoneStateListener = new MyPhoneStateListener();

启用

        telephonyManager.listen(phoneStateListener, LISTEN_CALL_STATE);

并禁用

    telephonyManager.listen(phoneStateListener,
            PhoneStateListener.LISTEN_NONE);

在哪里

        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
于 2013-05-13T05:06:37.200 回答