本文整理汇总了Java中android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES属性的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.MATCH_UNINSTALLED_PACKAGES属性的具体用法?Java PackageManager.MATCH_UNINSTALLED_PACKAGES怎么用?Java PackageManager.MATCH_UNINSTALLED_PACKAGES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.MATCH_UNINSTALLED_PACKAGES属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValidPackages
protected static HashSet<String> getValidPackages(Context context) {
// Initialize list of valid packages. This contain all the packages which are already on
// the device and packages which are being installed. Any item which doesn't belong to
// this set is removed.
// Since the loader removes such items anyway, removing these items here doesn't cause
// any extra data loss and gives us more free space on the grid for better migration.
HashSet validPackages = new HashSet<>();
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
for (PackageInfo info : context.getPackageManager()
.getInstalledPackages(uninstalled)) {
validPackages.add(info.packageName);
}
validPackages.addAll(PackageInstallerCompat.getInstance(context)
.updateAndGetActiveSessionCache().keySet());
return validPackages;
}
示例2: sendUninstallResult
/**
* Notifies the {@param callback} whether the uninstall was successful or not.
*
* Since there is no direct callback for an uninstall request, we check the package existence
* when the launch resumes next time. This assumes that the uninstall activity will finish only
* after the task is completed
*/
protected static void sendUninstallResult(
final Launcher launcher, boolean activityStarted,
final ComponentName cn, final UserHandle user,
final DropTargetResultCallback callback) {
if (activityStarted) {
final Runnable checkIfUninstallWasSuccess = new Runnable() {
@Override
public void run() {
// We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well.
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
boolean uninstallSuccessful = LauncherAppsCompat.getInstance(launcher)
.getApplicationInfo(cn.getPackageName(),
uninstalled, user) == null;
callback.onDragObjectRemoved(uninstallSuccessful);
}
};
launcher.addOnResumeCallback(checkIfUninstallWasSuccess);
} else {
callback.onDragObjectRemoved(false);
}
}
示例3: getPackageVersion
/**
* @return an array of containing versionCode and lastUpdatedTime for the package.
*/
@Thunk private long[] getPackageVersion(String packageName) {
synchronized (mPackageVersions) {
long[] versions = mPackageVersions.get(packageName);
if (versions == null) {
versions = new long[2];
try {
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
PackageInfo info = mContext.getPackageManager().getPackageInfo(packageName, uninstalled);
versions[0] = info.versionCode;
versions[1] = info.lastUpdateTime;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
mPackageVersions.put(packageName, versions);
}
return versions;
}
}
示例4: updateIconsForPkg
/**
* Updates the entries related to the given package in memory and persistent DB.
*/
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
removeIconsForPkg(packageName, user);
try {
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
PackageInfo info = mPackageManager.getPackageInfo(packageName,
uninstalled);
long userSerial = mUserManager.getSerialNumberForUser(user);
for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
addIconToDBAndMemCache(app, info, userSerial, false /*replace existing*/);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
return;
}
}
示例5: getEntryForPackageLocked
/**
* Gets an entry for the package, which can be used as a fallback entry for various components.
* This method is not thread safe, it must be called from a synchronized method.
*/
private CacheEntry getEntryForPackageLocked(String packageName, UserHandle user,
boolean useLowResIcon) {
ComponentKey cacheKey = getPackageKey(packageName, user);
CacheEntry entry = mCache.get(cacheKey);
if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
entry = new CacheEntry();
boolean entryUpdated = true;
// Check the DB first.
if (!getEntryFromDB(cacheKey, entry, useLowResIcon)) {
try {
int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;
int flags = Process.myUserHandle().equals(user) ? 0 : uninstalled;
PackageInfo info = mPackageManager.getPackageInfo(packageName, flags);
ApplicationInfo appInfo = info.applicationInfo;
if (appInfo == null) {
throw new NameNotFoundException("ApplicationInfo is null");
}
// Load the full res icon for the application, but if useLowResIcon is set, then
// only keep the low resolution icon instead of the larger full-sized icon
Bitmap icon = LauncherIcons.createBadgedIconBitmap(
appInfo.loadIcon(mPackageManager), user, mContext, appInfo.targetSdkVersion);
Bitmap lowResIcon = generateLowResIcon(icon, mPackageBgColor);
entry.title = appInfo.loadLabel(mPackageManager);
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
entry.icon = useLowResIcon ? lowResIcon : icon;
entry.isLowResIcon = useLowResIcon;
// Add the icon in the DB here, since these do not get written during
// package updates.
ContentValues values =
newContentValues(icon, lowResIcon, entry.title.toString(), packageName);
addIconToDB(values, cacheKey.componentName, info,
mUserManager.getSerialNumberForUser(user));
} catch (NameNotFoundException e) {
e.printStackTrace();
entryUpdated = false;
}
}
// Only add a filled-out entry to the cache
if (entryUpdated) {
mCache.put(cacheKey, entry);
}
}
return entry;
}