本文整理汇总了Java中android.content.pm.LauncherActivityInfo类的典型用法代码示例。如果您正苦于以下问题:Java LauncherActivityInfo类的具体用法?Java LauncherActivityInfo怎么用?Java LauncherActivityInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LauncherActivityInfo类属于android.content.pm包,在下文中一共展示了LauncherActivityInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getApplicationInfo
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
@Override
public ApplicationInfo getApplicationInfo(String packageName, int flags, UserHandle user) {
final boolean isPrimaryUser = Process.myUserHandle().equals(user);
if (!isPrimaryUser && (flags == 0)) {
// We are looking for an installed app on a secondary profile. Prior to O, the only
// entry point for work profiles is through the LauncherActivity.
List<LauncherActivityInfo> activityList =
mLauncherApps.getActivityList(packageName, user);
return activityList.size() > 0 ? activityList.get(0).getApplicationInfo() : null;
}
try {
ApplicationInfo info =
mContext.getPackageManager().getApplicationInfo(packageName, flags);
// There is no way to check if the app is installed for managed profile. But for
// primary profile, we can still have this check.
if (isPrimaryUser && ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0)
|| !info.enabled) {
return null;
}
return info;
} catch (PackageManager.NameNotFoundException e) {
// Package not found
return null;
}
}
示例2: startConfigActivity
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
@Override
public boolean startConfigActivity(Activity activity, int requestCode) {
if (getUser().equals(Process.myUserHandle())) {
return super.startConfigActivity(activity, requestCode);
}
try {
Method m = LauncherApps.class.getDeclaredMethod(
"getShortcutConfigActivityIntent", LauncherActivityInfo.class);
IntentSender is = (IntentSender) m.invoke(
activity.getSystemService(LauncherApps.class), mInfo);
activity.startIntentSenderForResult(is, requestCode, null, 0, 0, 0);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例3: onPackageAdded
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
@Override
public void onPackageAdded(String packageName, UserHandle user) {
String prefKey = INSTALLED_PACKAGES_PREFIX + mUserManager.getSerialNumberForUser(user);
HashSet<String> packageSet = new HashSet<>();
final boolean userAppsExisted = getUserApps(packageSet, prefKey);
if (!packageSet.contains(packageName)) {
List<LauncherActivityInfo> activities =
mLauncherApps.getActivityList(packageName, user);
if (!activities.isEmpty()) {
LauncherActivityInfo activityInfo = activities.get(0);
packageSet.add(packageName);
mPrefs.edit().putStringSet(prefKey, packageSet).apply();
onLauncherAppsAdded(Arrays.asList(
new LauncherActivityInstallInfo(activityInfo, System.currentTimeMillis())),
user, userAppsExisted);
}
}
}
示例4: updateIconsForPkg
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* 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: updateDbIcons
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
public void updateDbIcons(Set<String> ignorePackagesForMainUser) {
// Remove all active icon update tasks.
mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN);
mIconProvider.updateSystemStateString();
for (UserHandle user : mUserManager.getUserProfiles()) {
// Query for the set of apps
final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
// Fail if we don't have any apps
// TODO: Fix this. Only fail for the current user.
if (apps == null || apps.isEmpty()) {
return;
}
// Update icon cache. This happens in segments and {@link #onPackageIconsUpdated}
// is called by the icon cache when the job is complete.
updateDBIcons(user, apps, Process.myUserHandle().equals(user)
? ignorePackagesForMainUser : Collections.<String>emptySet());
}
}
示例6: addIconToDBAndMemCache
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Adds an entry into the DB and the in-memory cache.
* @param replaceExisting if true, it will recreate the bitmap even if it already exists in
* the memory. This is useful then the previous bitmap was created using
* old data.
*/
@Thunk private synchronized void addIconToDBAndMemCache(LauncherActivityInfo app,
PackageInfo info, long userSerial, boolean replaceExisting) {
final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
CacheEntry entry = null;
if (!replaceExisting) {
entry = mCache.get(key);
// We can't reuse the entry if the high-res icon is not present.
if (entry == null || entry.isLowResIcon || entry.icon == null) {
entry = null;
}
}
if (entry == null) {
entry = new CacheEntry();
entry.icon = LauncherIcons.createBadgedIconBitmap(getFullResIcon(app), app.getUser(),
mContext, app.getApplicationInfo().targetSdkVersion);
}
entry.title = app.getLabel();
entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
mCache.put(key, entry);
Bitmap lowResIcon = generateLowResIcon(entry.icon, mActivityBgColor);
ContentValues values = newContentValues(entry.icon, lowResIcon, entry.title.toString(),
app.getApplicationInfo().packageName);
addIconToDB(values, app.getComponentName(), info, userSerial);
}
示例7: convertToLauncherActivityIfPossible
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Tries to create a new PendingInstallShortcutInfo which represents the same target,
* but is an app target and not a shortcut.
* @return the newly created info or the original one.
*/
private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible(
PendingInstallShortcutInfo original) {
if (original.isLauncherActivity()) {
// Already an activity target
return original;
}
if (!Utilities.isLauncherAppTarget(original.launchIntent)) {
return original;
}
LauncherActivityInfo info = LauncherAppsCompat.getInstance(original.mContext)
.resolveActivity(original.launchIntent, original.user);
if (info == null) {
return original;
}
// Ignore any conflicts in the label name, as that can change based on locale.
return new PendingInstallShortcutInfo(info, original.mContext);
}
示例8: getView
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
ViewHolder holder = new ViewHolder();
if(convertView == null) {
convertView = mInflater.inflate(R.layout.app_list_item,null, false);
holder.icon = (ImageView)convertView.findViewById(R.id.icon);
holder.lable = (TextView)convertView.findViewById(R.id.label);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
LauncherActivityInfo appInfo = mData.get(position);
holder.icon.setImageDrawable(appInfo.getIcon(0));
holder.lable.setText(appInfo.getLabel());
return convertView;
}
示例9: getCustomShortcutActivityList
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
@Override
public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList(
@Nullable PackageUserKey packageUser) {
List<ShortcutConfigActivityInfo> result = new ArrayList<>();
UserHandle myUser = Process.myUserHandle();
try {
Method m = LauncherApps.class.getDeclaredMethod("getShortcutConfigActivityList",
String.class, UserHandle.class);
final List<UserHandle> users;
final String packageName;
if (packageUser == null) {
users = UserManagerCompat.getInstance(mContext).getUserProfiles();
packageName = null;
} else {
users = new ArrayList<>(1);
users.add(packageUser.mUser);
packageName = packageUser.mPackageName;
}
for (UserHandle user : users) {
boolean ignoreTargetSdk = myUser.equals(user);
List<LauncherActivityInfo> activities =
(List<LauncherActivityInfo>) m.invoke(mLauncherApps, packageName, user);
for (LauncherActivityInfo activityInfo : activities) {
if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >=
Build.VERSION_CODES.O) {
result.add(new ShortcutConfigActivityInfoVO(activityInfo));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例10: getAppShortcutInfo
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Make an ShortcutInfo object for a shortcut that is an application.
*/
public ShortcutInfo getAppShortcutInfo(
Intent intent, boolean allowMissingTarget, boolean useLowResIcon) {
if (user == null) {
return null;
}
ComponentName componentName = intent.getComponent();
if (componentName == null) {
return null;
}
Intent newIntent = new Intent(Intent.ACTION_MAIN, null);
newIntent.addCategory(Intent.CATEGORY_LAUNCHER);
newIntent.setComponent(componentName);
LauncherActivityInfo lai = LauncherAppsCompat.getInstance(mContext)
.resolveActivity(newIntent, user);
if ((lai == null) && !allowMissingTarget) {
return null;
}
final ShortcutInfo info = new ShortcutInfo();
info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
info.user = user;
info.intent = newIntent;
mIconCache.getTitleAndIcon(info, lai, useLowResIcon);
if (mIconCache.isDefaultIcon(info.iconBitmap, user)) {
Bitmap icon = loadIcon(info);
info.iconBitmap = icon != null ? icon : info.iconBitmap;
}
if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) {
info.isDisabled = ShortcutInfo.FLAG_DISABLED_SUSPENDED;
}
// from the db
if (TextUtils.isEmpty(info.title)) {
info.title = getTitle();
}
// fall back to the class name of the activity
if (info.title == null) {
info.title = componentName.getClassName();
}
info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
return info;
}
示例11: add
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Add the supplied ApplicationInfo objects to the list, and enqueue it into the
* list to broadcast when notify() is called.
*
* If the app is already in the list, doesn't add it.
*/
public void add(AppInfo info, LauncherActivityInfo activityInfo) {
if (!mAppFilter.shouldShowApp(info.componentName.getPackageName(), mContext)) {
return;
}
if (findActivity(data, info.componentName, info.user)) {
return;
}
mIconCache.getTitleAndIcon(info, activityInfo, true /* useLowResIcon */);
data.add(info);
added.add(info);
}
示例12: addPackage
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Add the icons for the supplied apk called packageName.
*/
public void addPackage(Context context, String packageName, UserHandle user) {
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
final List<LauncherActivityInfo> matches = launcherApps.getActivityList(packageName,
user);
for (LauncherActivityInfo info : matches) {
add(new AppInfo(context, info, user), info);
}
}
示例13: findActivity
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Returns whether <em>apps</em> contains <em>component</em>.
*/
private static boolean findActivity(List<LauncherActivityInfo> apps,
ComponentName component) {
for (LauncherActivityInfo info : apps) {
if (info.getComponentName().equals(component)) {
return true;
}
}
return false;
}
示例14: scheduleManagedHeuristicRunnable
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
private void scheduleManagedHeuristicRunnable(final ManagedProfileHeuristic heuristic,
final UserHandle user, final List<LauncherActivityInfo> apps) {
if (heuristic != null) {
// Assume the app lists now is updated.
mIsManagedHeuristicAppsUpdated = false;
final Runnable managedHeuristicRunnable = new Runnable() {
@Override
public void run() {
if (mIsManagedHeuristicAppsUpdated) {
// If app list is updated, we need to reschedule it otherwise old app
// list will override everything in processUserApps().
sWorker.post(new Runnable() {
public void run() {
final List<LauncherActivityInfo> updatedApps =
mLauncherApps.getActivityList(null, user);
scheduleManagedHeuristicRunnable(heuristic, user,
updatedApps);
}
});
} else {
heuristic.processUserApps(apps);
}
}
};
runOnMainThread(new Runnable() {
@Override
public void run() {
// Check isLoadingWorkspace on the UI thread, as it is updated on the UI
// thread.
if (mIsLoadingAndBindingWorkspace) {
synchronized (mBindCompleteRunnables) {
mBindCompleteRunnables.add(managedHeuristicRunnable);
}
} else {
runOnWorkerThread(managedHeuristicRunnable);
}
}
});
}
}
示例15: processUserApps
import android.content.pm.LauncherActivityInfo; //导入依赖的package包/类
/**
* Checks the list of user apps, and generates package event accordingly.
* {@see #onLauncherAppsAdded}, {@see #onLauncherPackageRemoved}
*/
void processUserApps(List<LauncherActivityInfo> apps, UserHandle user) {
String prefKey = INSTALLED_PACKAGES_PREFIX + mUserManager.getSerialNumberForUser(user);
HashSet<String> oldPackageSet = new HashSet<>();
final boolean userAppsExisted = getUserApps(oldPackageSet, prefKey);
HashSet<String> packagesRemoved = new HashSet<>(oldPackageSet);
HashSet<String> newPackageSet = new HashSet<>();
ArrayList<LauncherActivityInstallInfo> packagesAdded = new ArrayList<>();
for (LauncherActivityInfo info : apps) {
String packageName = info.getComponentName().getPackageName();
newPackageSet.add(packageName);
packagesRemoved.remove(packageName);
if (!oldPackageSet.contains(packageName)) {
oldPackageSet.add(packageName);
packagesAdded.add(new LauncherActivityInstallInfo(
info, info.getFirstInstallTime()));
}
}
if (!packagesAdded.isEmpty() || !packagesRemoved.isEmpty()) {
mPrefs.edit().putStringSet(prefKey, newPackageSet).apply();
if (!packagesAdded.isEmpty()) {
Collections.sort(packagesAdded);
onLauncherAppsAdded(packagesAdded, user, userAppsExisted);
}
if (!packagesRemoved.isEmpty()) {
for (String pkg : packagesRemoved) {
onLauncherPackageRemoved(pkg, user);
}
}
}
}