I have implemented two activity-alias
that the user should be able to enable or disable in runtime.
<activity-alias
android:name=".ui.alias.open_location"
android:targetActivity=".ui.activity.location"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
I do not want them to be enabled in the beginning, to not clutter up the app-screen of the users device. But in runtime, the user should be able to enable the alias. I do this via the PackageManager
:
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName componentName = new ComponentName(context, ".ui.alias.open_location");
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
This works like charm in the beginning, but the alias gets disabled again, when an update of my app is installed. How can I prevent the system from overwriting the enabled state by the manifest? I don't want the user to floot with Launcher in the beginning and I don't want the user to recreate all alias shortcuts after an update.
I think I would need something similar to PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
, but only for enabled state.
Thanks!