Example usage for android.content.pm PackageManager getActivityInfo

List of usage examples for android.content.pm PackageManager getActivityInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getActivityInfo.

Prototype

public abstract ActivityInfo getActivityInfo(ComponentName component, @ComponentInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve all of the information we know about a particular activity class.

Usage

From source file:com.cognizant.trumobi.PersonaLauncher.java

private static PersonaApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
    ComponentName component = data.getComponent();
    PackageManager packageManager = context.getPackageManager();
    ActivityInfo activityInfo = null;/*from   w  ww  .  j  av a  2 s.  c o m*/
    try {
        activityInfo = packageManager.getActivityInfo(component, 0 /*
                                                                   * no
                                                                   * flags
                                                                   */);
    } catch (NameNotFoundException e) {
        PersonaLog.e(LOG_TAG, "Couldn't find ActivityInfo for selected application", e);
    }

    if (activityInfo != null) {
        PersonaApplicationInfo itemInfo = new PersonaApplicationInfo();

        itemInfo.title = activityInfo.loadLabel(packageManager);
        if (itemInfo.title == null) {
            itemInfo.title = activityInfo.name;
        }

        itemInfo.setActivity(component,
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        // itemInfo.icon = activityInfo.loadIcon(packageManager);
        itemInfo.container = PersonaItemInfo.NO_ID;

        itemInfo.icon = PersonaLauncherModel.getIcon(packageManager, context, activityInfo);

        return itemInfo;
    }

    return null;
}

From source file:android.app.Activity.java

/**
 * Returns true if the app should recreate the task when navigating 'up' from this activity
 * by using targetIntent./*from w ww. j  a  va  2 s . co  m*/
 *
 * <p>If this method returns false the app can trivially call
 * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform
 * up navigation. If this method returns false, the app should synthesize a new task stack
 * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
 *
 * @param targetIntent An intent representing the target destination for up navigation
 * @return true if navigating up should recreate a new task stack, false if the same task
 *         should be used for the destination
 */
public boolean shouldUpRecreateTask(Intent targetIntent) {
    try {
        PackageManager pm = getPackageManager();
        ComponentName cn = targetIntent.getComponent();
        if (cn == null) {
            cn = targetIntent.resolveActivity(pm);
        }
        ActivityInfo info = pm.getActivityInfo(cn, 0);
        if (info.taskAffinity == null) {
            return false;
        }
        return !ActivityManagerNative.getDefault().targetTaskAffinityMatchesActivity(mToken, info.taskAffinity);
    } catch (RemoteException e) {
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}