FileDocCategorySizeDatePackage
LauncherActivityInfo.javaAPI DocAndroid 5.1 API5866Thu Mar 12 22:22:10 GMT 2015android.content.pm

LauncherActivityInfo

public class LauncherActivityInfo extends Object
A representation of an activity that can belong to this user or a managed profile associated with this user. It can be used to query the label, icon and badged icon for the activity.

Fields Summary
private static final String
TAG
private final PackageManager
mPm
private ActivityInfo
mActivityInfo
private android.content.ComponentName
mComponentName
private android.os.UserHandle
mUser
private long
mFirstInstallTime
Constructors Summary
LauncherActivityInfo(android.content.Context context, ResolveInfo info, android.os.UserHandle user, long firstInstallTime)
Create a launchable activity object for a given ResolveInfo and user.

param
context The context for fetching resources.
param
info ResolveInfo from which to create the LauncherActivityInfo.
param
user The UserHandle of the profile to which this activity belongs.


                                                
         
              
        this(context);
        mActivityInfo = info.activityInfo;
        mComponentName = LauncherApps.getComponentName(info);
        mUser = user;
        mFirstInstallTime = firstInstallTime;
    
LauncherActivityInfo(android.content.Context context)

        mPm = context.getPackageManager();
    
Methods Summary
public intgetApplicationFlags()
Returns the application flags from the ApplicationInfo of the activity.

return
Application flags
hide
remove before shipping

        return mActivityInfo.applicationInfo.flags;
    
public ApplicationInfogetApplicationInfo()
Returns the application info for the appliction this activity belongs to.

return

        return mActivityInfo.applicationInfo;
    
public android.graphics.drawable.DrawablegetBadgedIcon(int density)
Returns the activity icon with badging appropriate for the profile.

param
density Optional density for the icon, or 0 to use the default density. Use {@link DisplayMetrics} for DPI values.
see
DisplayMetrics
return
A badged icon for the activity.

        int iconRes = mActivityInfo.getIconResource();
        Resources resources = null;
        Drawable originalIcon = null;
        try {
            resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo);
            try {
                if (density != 0) {
                    originalIcon = resources.getDrawableForDensity(iconRes, density);
                }
            } catch (Resources.NotFoundException e) {
            }
        } catch (NameNotFoundException nnfe) {
        }

        if (originalIcon == null) {
            originalIcon = mActivityInfo.loadIcon(mPm);
        }

        if (originalIcon instanceof BitmapDrawable) {
            return mPm.getUserBadgedIcon(originalIcon, mUser);
        } else {
            Log.e(TAG, "Unable to create badged icon for " + mActivityInfo);
        }
        return originalIcon;
    
public android.content.ComponentNamegetComponentName()
Returns the component name of this activity.

return
ComponentName of the activity

        return mComponentName;
    
public longgetFirstInstallTime()
Returns the time at which the package was first installed.

return
The time of installation of the package, in milliseconds.

        return mFirstInstallTime;
    
public android.graphics.drawable.DrawablegetIcon(int density)
Returns the icon for this activity, without any badging for the profile.

param
density The preferred density of the icon, zero for default density. Use density DPI values from {@link DisplayMetrics}.
see
#getBadgedIcon(int)
see
DisplayMetrics
return
The drawable associated with the activity

        // TODO: Use density
        return mActivityInfo.loadIcon(mPm);
    
public java.lang.CharSequencegetLabel()
Retrieves the label for the activity.

return
The label for the activity.

        return mActivityInfo.loadLabel(mPm);
    
public java.lang.StringgetName()
Returns the name for the acitivty from android:name in the manifest.

return
the name from android:name for the acitivity.

        return mActivityInfo.name;
    
public android.os.UserHandlegetUser()
Returns the user handle of the user profile that this activity belongs to. In order to persist the identity of the profile, do not store the UserHandle. Instead retrieve its serial number from UserManager. You can convert the serial number back to a UserHandle for later use.

see
UserManager#getSerialNumberForUser(UserHandle)
see
UserManager#getUserForSerialNumber(long)
return
The UserHandle of the profile.

        return mUser;