根据packagename启动apk:
Intent mintent =activity.getPackageManager().getLaunchIntentForPackage(Packagename); activity.startActivity(mintent);
判断已安装的apk属于系统还是用户:
List<PackageInfo> appPackage =activity.getPackageManager().getInstalledPackages(0); for (int i = 0; i < appPackage.size(); i++) { PackageInfo temp = appPackage.get(i); ApplicationInfo appInfo = temp.applicationInfo; if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0) issystemapk=true; else isuserapk=true; }
根据intent查询activity的ResolveInfo集合:
Intent intent = new Intent("com.android.mslauncher.SETWALLPAPERSET"); PackageManager pm = getPackageManager(); List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (apps == null || apps.size() == 0) Log.d(TAG, "cannot find app with action : com.android.mslauncher.SETWALLPAPERSET");
public abstractResolveInfo resolveActivity(Intent intent, int flags)
参数: intent 查寻条件,Activity所配置的action和category
flags: MATCH_DEFAULT_ONLY :Category必须带有CATEGORY_DEFAULT的Activity,才匹配
GET_INTENT_FILTERS :匹配Intent条件即可
GET_RESOLVED_FILTER :匹配Intent条件即可
功能 :返回给定条件的ResolveInfo对象(本质上是Activity)
public abstract List<ResolveInfo> queryIntentActivities(Intent intent, int flags)
参数同上
功能 :返回给定条件的所有ResolveInfo对象(本质上是Activity),集合对象
public abstract List<ApplicationInfo> getInstalledApplications(int flags)
参数:flag为一般为GET_UNINSTALLED_PACKAGES,那么此时会返回所有ApplicationInfo。我们可以对ApplicationInfo
的flags过滤,得到我们需要的。
功能:返回给定条件的所有PackageInfo
通过 PackageInfo 获取具体信息方法:
包名获取方法:packageInfo.packageName
icon获取获取方法:packageManager.getApplicationIcon(applicationInfo)
应用名称获取方法:packageManager.getApplicationLabel(applicationInfo)
使用权限获取方法:packageManager.getPackageInfo(packageName,PackageManager.GET_PERMISSIONS)
.requestedPermissions
通过 ResolveInfo 获取具体信息方法:
包名获取方法:resolve.activityInfo.packageName
icon获取获取方法:resolve.loadIcon(packageManager)
应用名称获取方法:resolve.loadLabel(packageManager).toString()