i'm creating a launcher app and i would like to show the default launcher chooser manually.
I already found and tried this but this is not perfect, since i cannot select ALWAYS immediately. After choosing the launcher i need to press the home button to be able to select ALWAYS.
This is my code:
public static void resetPreferredLauncherAndOpenChooser(Context context) {
PackageManager packageManager = context.getPackageManager();
ComponentName componentName = new ComponentName(context, DefaultLauncherHelperActivity.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
selector.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(selector);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
}
and here the manifest:
<activity
android:name=".activities.MainActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".activities.DefaultLauncherHelperActivity"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This is what i get (left) vs. what i'm trying to achieve (right)
There has to be a way since Microsoft's launcher and the poco launcher are able to do this but i couldn't find a solution and unfortunately there is no open source launcher with the same functionality. Can anyone help me with this?