Android 如何在应用程序抽屉中获取所有应用程序?
我用这个从包名打开应用程序Android 如何在应用程序抽屉中获取所有应用程序?,android,android-package-managers,android-applicationinfo,Android,Android Package Managers,Android Applicationinfo,我用这个从包名打开应用程序 startActivity(getPackageManager().getLaunchIntentForPackage("packagename")); android中的许多应用程序无法打开,因为它们是系统包,而不是应用程序。这些软件包无法打开 e、 g 我使用此方法过滤掉所有systempackage private boolean isSystemPackage(PackageInfo pkgInfo) { Log.v("sys", String.fo
startActivity(getPackageManager().getLaunchIntentForPackage("packagename"));
android中的许多应用程序无法打开,因为它们是系统包,而不是应用程序。这些软件包无法打开
e、 g
我使用此方法过滤掉所有systempackage
private boolean isSystemPackage(PackageInfo pkgInfo)
{
Log.v("sys", String.format("%31s", Integer.toBinaryString(pkgInfo.applicationInfo.flags)).replace(' ', '0') +" : "+ pkgInfo.packageName+" : "+(((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true:false)+" : "+pkgInfo.applicationInfo.loadLabel(pm).toString());
Log.v("sys", String.format("%31s", Integer.toBinaryString(ApplicationInfo.FLAG_SYSTEM)).replace(' ', '0') +" : "+ pkgInfo.packageName+" : "+(((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true:false)+" : "+pkgInfo.applicationInfo.loadLabel(pm).toString());
return ((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) ? true:false;
}
但此方法无法帮助我确定哪个软件包不是系统应用程序
比如说
这是LG g pro 2中的whatsapp
V/sys﹕ 0000000110010000011111001000100 : com.whatsapp : false : WhatsApp
V/sys﹕ 0000000000000000000000000000001 : com.whatsapp : false : WhatsApp
这在注4中
V/sys﹕ 0000000110010000011111011000101 : com.whatsapp : true : WhatsApp
V/sys﹕ 0000000000000000000000000000001 : com.whatsapp : true : WhatsApp
这是一个特例,我不明白为什么某些设备中的whatsapp是系统包
另一个例子
V/sys﹕ 0000000110110001011111011000101 : com.google.android.apps.plus : true : Google+
V/sys﹕ 0000000000000000000000000000001 : com.google.android.apps.plus : true : Google+
我知道google+是默认安装的,所以它是一个系统包,但它在应用程序抽屉中
所以我认为FLAG_系统不适合在android中获得所有应用
如何获取应用程序抽屉中的所有应用程序
更新: 现在我用这种方式获取所有应用程序
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, 0);
PackageManager pm = getPackageManager();
for(ResolveInfo ri : resolveInfoList)
{
String appName=ri.activityInfo.loadLabel(pm).toString();
Drawable icon=ri.loadIcon(pm);
Log.v("sys",ri.activityInfo.packageName +":" + appName);
}
但是没有人在工作,有些人可能会使我的应用程序崩溃。你可以这样做:
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> resolveInfoList = ctx.getPackageManager().queryIntentActivities(mainIntent, 0);
final Intent Intent=新意图(Intent.ACTION\u MAIN,空);
intent.addCategory(intent.CATEGORY_启动器);
最终列表resolveInfoList=ctx.getPackageManager().QueryInputActivities(mainIntent,0);
有关更多详细信息,请查看此启动器的来源:
您可以这样做:
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final List<ResolveInfo> resolveInfoList = ctx.getPackageManager().queryIntentActivities(mainIntent, 0);
final Intent Intent=新意图(Intent.ACTION\u MAIN,空);
intent.addCategory(intent.CATEGORY_启动器);
最终列表resolveInfoList=ctx.getPackageManager().QueryInputActivities(mainIntent,0);
有关更多详细信息,请查看此启动器的来源:
希望在启动器中可见的活动必须指定特定的
意图过滤器
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
希望在启动器中可见的活动必须指定特定的意图过滤器
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
“这些包不可打开
”什么是“可打开”包?抽屉里的那个?如果是这样,请参见ligi的回答对不起,请更正以下文字“这些包不可打开”
“可打开”包是什么?抽屉里的那个?如果是这样的话,请看ligi的回答对不起,只需更正单词。这种方式有效,但仍有一些问题,我将根据此答案更新我的问题库。这种方式有效,但仍有一些问题,我将根据此答案更新我的问题库。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
List<ResolveInfo> list = packageManager.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), 0);