java - How to reset default launcher/home screen replacement? -
When the user clicks on the home then he is given the option of the launcher and he can also decide whether to default The problem is whether or not it is difficult to change it again later.
To fix this, I have a "Reset Preferred Launcher" that turns it on:
getPackageManager (). ClearPackagePreferredActivities getPackageName ()); However, this line only resets the preferred launcher if it has chosen my launcher. I need a snippet that cleanses the favorite launcher, so the next time the user clicks on the home, the option is redistributed.
This is not directly possible, and Android developers have said that they will not allow an app to alter the user's preferences However, there is an alternative solution based on how these options maintain Android.
Look like your manifest:
& lt; Activity Android: name = "MyLauncherActivity" Android: exported = "true" /> & Lt; Activity- alias android: name = "LauncherAlias1" Android: targetActivity = "MyLauncherActivity" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.intent.action.MAIN" /> & Lt; Category android: name = "android.intent.category.HOME" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; / Intent-Filter & gt; & Lt; / Activity alias & gt; & Lt; Activity- alias android: name = "LauncherAlias2" Android: enabled = "false" android: targetActivity = "MyLauncherActivity" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.intent.action.MAIN" /> & Lt; Category android: name = "android.intent.category.HOME" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; / Intent-Filter & gt; & Lt; / Activity alias & gt; For the sake of simplicity, I have left the extra features which are not relevant for the work at hand. Anyway when you appear, you can clear the default launcher using code like this:
PackageManager pm = getPackageManager (); Component-cn1 = new element name ("com.mypackage", "com.mypackage.LauncherAlias1"); Component name cn2 = new element name ("com.mypackage", "com.mypackage.LauncherAlias2"); Int dis = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; If (pm.getComponentEnabledSetting (cn1) == dis) dis = 3 - dis; Pm.setComponentEnabledSetting (cn1, dis, PackageManager.DONT_KILL_APP); Pm.setComponentEnabledSetting (cn2, 3-dis, PackageManager.DONT_KILL_APP); By enabling a nickname and disabling the other, you agree to replace Android with the user's choice, as if you have installed a launcher and uninstalled the other. Thus, the next time they press the Home button, the user will be asked to choose again. This approach does not matter which launcher is current default.
Comments
Post a Comment