我想获取当前安装的当前启动器的包名。我尝试使用链接http://stackoverflow.com/questions/10344824/how-can-i-get-the-package-name-of-the-current-launcher-in-android-2-3-and-above
但它将结果显示为“android”。我想要完整的启动器名称。
我想安装启动器列表并选择当前启动器
提前致谢
答案 0 :(得分:20)
您好,您可以使用以下代码获取当前的启动器包名称:
PackageManager localPackageManager = getPackageManager();
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
String str = localPackageManager.resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY).activityInfo.packageName;
Log.e("Current launcher Package Name:",str);
答案 1 :(得分:2)
作为联邦在Get a list of every launcher in Android
中的回答获取所有已安装启动器的列表。
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> lst = getPackageManager().queryIntentActivities(intent, 0);
if (!lst.isEmpty()) {
for (ResolveInfo resolveInfo : lst) {
Log.d("Test", "New Launcher Found: " + resolveInfo.activityInfo.packageName);
}
}
答案 2 :(得分:0)
以下代码可以完美地获取当前启动器应用程序包的名称。
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
String currentLauncherName= resolveInfo.activityInfo.packageName;
Log.d("Current Launcher: ", currentLauncherName);