|
@@ -18,6 +18,9 @@ import java.util.ArrayList;
|
18
|
18
|
import java.util.List;
|
19
|
19
|
|
20
|
20
|
public class AppUtils {
|
|
21
|
+ /**
|
|
22
|
+ * 获得不包含自己的app列表
|
|
23
|
+ */
|
21
|
24
|
public static List<AppInfo> GetAppList(Context context) {
|
22
|
25
|
List<AppInfo> list = new ArrayList<>();
|
23
|
26
|
List<String> pkgList=new ArrayList<>();
|
|
@@ -59,6 +62,49 @@ public class AppUtils {
|
59
|
62
|
return list;
|
60
|
63
|
}
|
61
|
64
|
|
|
65
|
+ /**
|
|
66
|
+ * 获得包含自己的app列表
|
|
67
|
+ */
|
|
68
|
+ public static List<AppInfo> GetAllAppList(Context context) {
|
|
69
|
+ List<AppInfo> list = new ArrayList<>();
|
|
70
|
+ List<String> pkgList=new ArrayList<>();
|
|
71
|
+ PackageManager pm = context.getPackageManager();
|
|
72
|
+ Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
|
|
73
|
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
74
|
+ List<ResolveInfo> activities = pm.queryIntentActivities(mainIntent, 0);
|
|
75
|
+ for (ResolveInfo info : activities) {
|
|
76
|
+ String packName = info.activityInfo.packageName;
|
|
77
|
+ //去重
|
|
78
|
+ if (pkgList.contains(packName)) {
|
|
79
|
+ continue;
|
|
80
|
+ }
|
|
81
|
+ AppInfo mInfo = new AppInfo();
|
|
82
|
+ mInfo.setIco(info.activityInfo.applicationInfo.loadIcon(pm));
|
|
83
|
+ mInfo.setName(info.activityInfo.applicationInfo.loadLabel(pm).toString());
|
|
84
|
+ mInfo.setPackageName(packName);
|
|
85
|
+ pkgList.add(packName);
|
|
86
|
+ try {
|
|
87
|
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packName, PackageManager.GET_META_DATA);
|
|
88
|
+ mInfo.setVersionName(packageInfo.versionName);
|
|
89
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
|
|
90
|
+ mInfo.setVersionNum(packageInfo.getLongVersionCode());
|
|
91
|
+ }else {
|
|
92
|
+ mInfo.setVersionNum(packageInfo.versionCode);
|
|
93
|
+ }
|
|
94
|
+ } catch (PackageManager.NameNotFoundException e) {
|
|
95
|
+ throw new RuntimeException(e);
|
|
96
|
+ }
|
|
97
|
+ // 为应用程序的启动Activity 准备Intent
|
|
98
|
+ Intent launchIntent = new Intent();
|
|
99
|
+ launchIntent.setComponent(new ComponentName(packName,
|
|
100
|
+ info.activityInfo.name));
|
|
101
|
+ launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
102
|
+ mInfo.setIntent(launchIntent);
|
|
103
|
+ list.add(mInfo);
|
|
104
|
+ }
|
|
105
|
+ return list;
|
|
106
|
+ }
|
|
107
|
+
|
62
|
108
|
/**
|
63
|
109
|
* 判断应用是否已经安装
|
64
|
110
|
*/
|