Lru的全称是Least Recently Used ,近期最少使用的!LruCache 的实现原理:把近期最少使用的数据从缓存中移除,保留使用最频繁的数据
private ArrayList<AppInfo> getAppInfo() {
ArrayList<AppInfo> appList = new ArrayList<>();//存储应用信息
List<PackageInfo> packageInfos = getPackageManager().getInstalledPackages(0);
for (int i = 0; i < packageInfos.size(); i++) {
PackageInfo packageInfo = packageInfos.get(i);
AppInfo appInfo = new AppInfo();
appInfo.appName = packageInfo.applicationInfo.loadLabel(getPackageManager()).toString();
appInfo.packageName = packageInfo.packageName;
appInfo.versionCode = packageInfo.versionCode;
appInfo.appIcon = packageInfo.applicationInfo.loadIcon(getPackageManager());
//非系统应用
if((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
appList.add(appInfo);
}
// 桌面应用的启动在INTENT中需要包含ACTION_MAIN 和CATEGORY_HOME.
ArrayList<AppInfo> appList = new ArrayList<>();//存储应用信息
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setAction(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
List<ResolveInfo> list = manager.queryIntentActivities(intent, 0);
// List<PackageInfo> packageInfos = manager.getInstalledPackages(0);
for (int i = 0; i < list.size(); i++) {
AppInfo appInfo = new AppInfo();
ResolveInfo resolveInfo = list.get(i);
appInfo.appName = resolveInfo.loadLabel(manager).toString();
appInfo.packageName = resolveInfo.activityInfo.packageName.toString();
appInfo.mBitmapBytes = BitmapDrawableExchange.drawableToBytes(resolveInfo.loadIcon(manager));
// appInfo.appIcon = (BitmapDrawable) resolveInfo.loadIcon(manager);
if (!appInfo.packageName.equals("com.example.myapplication")) {
boolean flag = true;
if (addedList.size() != 0) {
for (int j = 0; j < addedList.size(); j++) {
if (appInfo.packageName.equals(addedList.get(j).packageName)) {
flag = false;
}
}
}
if (flag)
appList.add(appInfo);
}
public void startApp(String packageName) {
Intent intent = MainActivity.this.getPackageManager()
.getLaunchIntentForPackage(packageName);
// 已安装包 直接启动
if (intent != null) {
startActivity(intent);
}
}