Hi I'm trying to create an application to change the launcher on an Android device using the following function:
private void changeLauncher() {
getPackageManager().clearPackagePreferredActivities(getPackageName());
Intent selector = new Intent("android.intent.action.MAIN");
selector.addCategory("android.intent.category.HOME");
selector.setComponent(new ComponentName("android", "com.android.internal.app.ResolverActivity"));
startActivity(selector);
}
It works for all Android devices but force closes on the LG G3 running Android 5.0. However it does work for another Android 5.0 device (Asus K19 Fonepad). What can i do to solve it ?
Change the method to:
private void changeLauncher() {
getPackageManager().clearPackagePreferredActivities(getPackageName());
Intent selector = new Intent(Intent.ACTION_MAIN);
selector.addCategory(Intent.CATEGORY_HOME);
startActivity(selector);
}
You seem to be trying to launch the chooser activity directly, rather than specifying an Intent
and letting Android populate the list of activities itself, which is the correct usage of the resolver.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.