问题
It's been now a long time since I try to figure out how to develop a android unlock screen app working with an NFC authentication. I am working with a Nexus S. After several researches on the Internet, I came to the conclusion that replacing the lock screen as a third party app is just not supported right now and that we need to modify the platform to do a decent implementation.
This is the reason why I developed an home screen app that give the illusion of an unlockscreen app. But my problem is that I would like to be redirect to the default laucher at the end of the procedure.
I first tried with the code below but the problem is that I will have the choice between the default home screen and my new app
Intent goHome = new Intent();
i.setAction("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
startActivity(goHome);
So I then I tried with the code below but it doesn't seem to work.
Intent goHome = new Intent(Intent.ACTION_MAIN);
goHome.setClassName("com.android.launcher", "com.android.launcher.Launcher");
startActivity(goHome);
I get the following logCat
Unable to find explicit activity class ( com.android.launcher.laucher)
Do you have any idea why it doesn't work? Is it the right way of doing it?
回答1:
try this :
goHome.setClassName("com.android.launcher", "com.android.launcher2.Launcher");
回答2:
Use:
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
if (lst != null) {
for (ResolveInfo resolveInfo : lst) {
try {
Intent home = new Intent("android.intent.action.MAIN");
home.addCategory("android.intent.category.HOME");
home.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
startActivity(home);
break;
} catch (Throwable t) {
t.printStackTrace();
}
}
}
回答3:
In case you have a Samsung device, the following code worked for me:
Intent goHome = new Intent(Intent.ACTION_MAIN);
goHome.setClassName("com.sec.android.app.launcher", "com.android.launcher2.Launcher");
startActivity(goHome);
来源:https://stackoverflow.com/questions/9787658/how-to-redirect-user-to-default-launcher-in-an-android-app