private void checkSavedApps() { List<AppItem> cache = mDataManager.getCache(); List<ApplicationInfo> allAppInfos = mDataManager.getAllAppInfos(); for (AppItem next : cache) { boolean currHas = false; for (ApplicationInfo applicationInfo : allAppInfos) { if (applicationInfo.packageName.equals(next.getPackageName())) { currHas = true; break; } } if (!currHas) { deleteApp(next); LOGGER.i(TAG, "delete = " + next); } } }
@NonNull private AppItem getAppItem(ApplicationInfo next) throws SQLException, FileNotFoundException { AppItem appitem = new AppItem(); appitem.setName(next.loadLabel(mPackageManager).toString()); appitem.setPinyin(Utils.getPinyinNum(appitem.getName().replace(" ", ""))); appitem.setFullpinyin(Utils.getPinyinNum(appitem.getName().replace(" ", ""), true)); appitem.setPackageName(next.packageName); Drawable drawable = next.loadIcon(mPackageManager); Bitmap bitmap = Utils.drawableToBitmap(drawable); String path = Utils.generateFilePath(getContext(), appitem.getPackageName()); bitmap.compress(Bitmap.CompressFormat.PNG, 100, new FileOutputStream(path)); appitem.setImage(path); return appitem; }
private void checkCurrApps() { List<ApplicationInfo> allAppInfos = mDataManager.getAllAppInfos(); List<AppItem> cache = mDataManager.getCache(); for (ApplicationInfo next : allAppInfos) { boolean hasSave = false; for (AppItem appItem : cache) { if (appItem.getPackageName().equals(next.packageName)) { hasSave = true; } } if (!hasSave) { try { AppItem appItem = getAppItem(next); saveAppItem(appItem); LOGGER.i(TAG, "add = " + appItem); } catch (SQLException | FileNotFoundException e) { e.printStackTrace(); } } } }