Skip to content Skip to sidebar Skip to footer

Automatically Revert To Previous Default Sms App

I have an app that requires temporary access to the device's SMS. In KitKat and above, this access is only granted to the default SMS app, so I'm using: Intent intent = new Intent(

Solution 1:

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(newComponentName(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.

Post a Comment for "Automatically Revert To Previous Default Sms App"