推荐方法
1、
private void queryFilterAppInfo() {
PackageManager pm = this.getPackageManager();
// 查询所有已经安装的应用程序
List<ApplicationInfo> listAppcations = pm.getInstalledApplications
(
PackageManager.GET_UNINSTALLED_PACKAGES);
//
GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的
for (ApplicationInfo app : listAppcations) {
AppInfo appInfo = new AppInfo();
appInfo.setAppLabel((String) app.loadLabel(pm));
appInfo.setAppIcon(app.loadIcon(pm));
appInfo.setPkgName(app.packageName);
mlistAppInfo.add(appInfo);
}
2、
public void querySysAppInfo() {
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 通过查询,获得所有ResolveInfo对象.
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo reInfo : resolveInfos) {
String activityName = reInfo.activityInfo.name; // 获得该应用程序的启动Activity的name
String pkgName = reInfo.activityInfo.packageName; // 获得应用程序的包名
String appLabel = (String) reInfo.loadLabel(pm); // 获得应用程序的Label
Drawable icon = reInfo.loadIcon(pm); // 获得应用程序图标
System.out.println(appLabel + " activityName---" + activityName
+ " pkgName---" + pkgName);
}
3、
//最简单的方法
public
boolean appIsInstalled(String packageName){
try {
PackageManager pm = this.getPackageManager();
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
System.out.println("已安装"+packageName);
} catch (NameNotFoundException e) {
System.out.println("没有安装"+packageName);
return false;
}
return true;
}
4、//
获得所有包信息
public void getInstallPackage() {
PackageManager packageManager = this.getPackageManager();
List<PackageInfo>
packageInfoList=packageManager.getInstalledPackages(0);
mlistAppInfo.clear();
}
5、
//直接启动方法
public
void srartApp(String packageName){
}