Automatically revert to previous default SMS app

浪子不回头ぞ 提交于 2019-12-03 16:26:17

To be eligible to be the default messaging app, your app has to have certain active components registered in the manifest. Disabling any one of them will make your app ineligible, and the system should automatically revert the default. We can use the PackageManager#setComponentEnabledSetting() method to disable a manifest-registered component.

For example, if the Receiver you have registered for the SMS_DELIVER action is named SmsReceiver:

getPackageManager()
    .setComponentEnabledSetting(new ComponentName(this, SmsReceiver.class),
                                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                                PackageManager.DONT_KILL_APP);

Obviously, before your app could be set as the default again, you would need to re-enable that component, which you can do by calling the above method with PackageManager.COMPONENT_ENABLED_STATE_ENABLED as the second argument.

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