我在使用模拟器时通过以下代码成功启动了默认主页启动器:
Intent de_intent=new Intent();
de_intent.setClassName("com.android.launcher","com.android.launcher2.Launcher");
startActivity(de_intent);
但是当我在真实设备上执行这段代码时,它显示如下异常:
Unable to find explicit activity class {com.android.launcher/com.android.launcher2.Launcher} have you declared this in AndroidManifest.xml
谁能帮我解决这个问题?
最佳答案
您有三星设备吗?他们用 TouchWiz Home 启动器替换了默认的 Android 启动器。以下代码使用 setClassName() 方法为我工作:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.sec.android.app.launcher", "com.android.launcher2.Launcher");
startActivity(intent);
关于android - 如何在使用真实设备时通过代码启动默认主页启动器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13345351/