How do I programmatically launch the "correct" default launcher? Labels lose their name
What I have done so far:
I am facing some issues with the launchers. My app is adding shortcuts to the launcher workspace (desktop). But on some devices (Samsum Duos), for example, names and / or icons changed after rebooting to my default app.
So, I am currently looking at 1000 lines of code in android source to identify the problem, but couldn't find it.
I saw in InstallShortcutReceiver a
comment on line 183 that the "name" provided Intent.EXTRA_SHORTCUT_NAME
may some situations only be used for comparison, etc. and will be replaced with the default application name.
// This name is only used for comparisons and notifications, so fall back to activity name
// if not supplied
But (my Samsum Duos is rooted) I could find complete information about cell position and shortcutInfo inside launcher.db .
So after a reboot it was not , but it may not have been initialized correctly!
- First question:
Does anyone know the reason for creating a custom, programmatically generated shortcut to change the title and icon to the application that created it?
Next story:
I noticed that this question was reproducible on my Samsum Duos, so I decided to exclude "Install Devices" from the "Save Launcher" list.
To get the default launcher I do the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = null;
try {
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); //can return null!
}catch(RuntimeException e){
ExceptionHandler.logAndSendException(e);//package manager has died
return false;
}
But now the problem is that it always returns that the default launchers package: com.android.launcher2.Launcher
which will be the default android. But I know that Samsum uses the TouchWiz home
package which is under com.sec.android.app.launcher ! This is also where I found launcher.db and all of its ShortcutInfo.
2. Second question
How can I reproduce the correct default launcher to identify which launcher is being used?
change
I kind of fixed the second issue. Somehow the ResolveInfo I get from the PackageManager does n't look reliable .
For Samsum Duos I get:
resolveInfo.activityInfo.name = com.android.launcher2.Launcher
resolveInfo.activityInfo.packageName = com.sec.android.app.launcher //this is what I need
But for Redmi MIUI:
resolveInfo.activityInfo.name = com.miui.home.launcher.Launcher //this time I would need this
resolveInfo.activityInfo.packageName = com.miui.home //the packageName is not complete!
I need a unique ID to run! So I thought activityInfo.name would be the path, but that is not in some situations. And packageManager seems to be applied to too many devices. Any suggestions?
Hooray!
source to share
No one has answered this question yet
Check out similar questions: