List of usage examples for android.content.pm PackageManager getActivityInfo
public abstract ActivityInfo getActivityInfo(ComponentName component, @ComponentInfoFlags int flags) throws NameNotFoundException;
From source file:Main.java
public static Intent getDefaultAlarmsIntent(Context context) { // TODO: consider using AlarmClock.ACTION_SET_ALARM, although it requires a permission PackageManager pm = context.getPackageManager(); for (String packageName : CLOCK_PACKAGES) { try {/*w w w .j a va2s . c o m*/ ComponentName cn = new ComponentName(packageName, "com.android.deskclock.AlarmClock"); pm.getActivityInfo(cn, 0); return Intent.makeMainActivity(cn); } catch (PackageManager.NameNotFoundException ignored) { } } return getDefaultClockIntent(context); }
From source file:Main.java
public static String getAppName(Context context, Intent appIntent) { if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) { return appIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); }/* w ww.j a va2 s .c om*/ if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)) { appIntent = appIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); } ComponentName componentName = appIntent.getComponent(); PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = null; ActivityInfo activityInfo = null; try { appInfo = pm.getApplicationInfo(componentName.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { appInfo = null; } try { activityInfo = pm.getActivityInfo(componentName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } if (appInfo == null) { return null; } else { CharSequence appName = pm.getApplicationLabel(appInfo); CharSequence activityName = null; if (activityInfo != null) { activityName = activityInfo.loadLabel(pm); } if (activityName != null) { return activityName.toString(); } if (appName != null) { appName.toString(); } return null; } }
From source file:com.android.launcher3.InstallShortcutReceiver.java
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead./*from ww w. j a v a 2s. c o m*/ */ private static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
From source file:com.vinexs.tool.Utility.java
public static String getAppName(Activity activity) { try {//from w w w . ja v a2s . co m PackageManager packageMgr = activity.getPackageManager(); ActivityInfo activityInfo = packageMgr.getActivityInfo(activity.getComponentName(), 0); return activityInfo.loadLabel(packageMgr).toString(); } catch (Exception e) { return ""; } }
From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java
/** * Ensures that we have a valid, non-null name. If the provided name is null, we will return * the application name instead./* ww w .j a va 2 s.c o m*/ */ @Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) { if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm); } catch (PackageManager.NameNotFoundException nnfe) { return ""; } } return name; }
From source file:net.lp.actionbarpoirot.helpers.DualNavUtils.java
/** * Return the fully qualified class name of a source activity's parent * activity as specified by a {@link #PARENT_ACTIVITY} <meta-data> * element within the activity element in the application's manifest. The * source activity is provided by componentName. * //from w w w . j a va 2 s . c o m * @param context * Context for looking up the activity component for the source * activity * @param componentName * ComponentName for the source Activity * @return The fully qualified class name of sourceActivity's parent * activity or null if it was not specified */ public static String getParentActivityName(Context context, ComponentName componentName) throws NameNotFoundException { final PackageManager pm = context.getPackageManager(); final ActivityInfo info = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA); return getParentActivityNameInner(context, info); }
From source file:android.support.v7.app.ActionBarActivityDelegate.java
protected final String getUiOptionsFromMetadata() { try {//from w w w . j av a2 s . c om PackageManager pm = mActivity.getPackageManager(); ActivityInfo info = pm.getActivityInfo(mActivity.getComponentName(), PackageManager.GET_META_DATA); String uiOptions = null; if (info.metaData != null) { uiOptions = info.metaData.getString(METADATA_UI_OPTIONS); } return uiOptions; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "getUiOptionsFromMetadata: Activity '" + mActivity.getClass().getSimpleName() + "' not in manifest"); return null; } }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;// w w w . j a v a 2 s . co m } if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0)); Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); if (intent == null) { return; } // This name is only used for comparisons and notifications, so fall back to activity name // if not supplied String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return; } } Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Queue the item up for adding if launcher has not loaded properly yet LauncherAppState.setApplicationContext(context.getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); boolean launcherNotLoaded = (app.getDynamicGrid() == null); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info); if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }
From source file:com.llf.android.launcher3.InstallShortcutReceiver.java
@Override public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;/*www .ja v a 2s . c o m*/ } if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0)); Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); if (intent == null) { return; } // This name is only used for comparisons and notifications, so fall // back to activity name // if not supplied String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return; } } Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Queue the item up for adding if launcher has not loaded properly yet LauncherAppState.setApplicationContext(context.getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); boolean launcherNotLoaded = (app.getDynamicGrid() == null); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info); if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }
From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java
public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return;// w w w .j a va2 s . com } if (DBG) Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0)); Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); if (intent == null) { return; } // This name is only used for comparisons and notifications, so fall // back to activity name // if not supplied String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); if (name == null) { try { PackageManager pm = context.getPackageManager(); ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0); name = info.loadLabel(pm).toString(); } catch (PackageManager.NameNotFoundException nnfe) { return; } } Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); // Queue the item up for adding if launcher has not loaded properly yet LauncherAppState.setApplicationContext(context.getApplicationContext()); LauncherAppState app = LauncherAppState.getInstance(); boolean launcherNotLoaded = (app.getDynamicGrid() == null); PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); addToInstallQueue(sp, info); if (!mUseInstallQueue && !launcherNotLoaded) { flushInstallQueue(context); } }