List of usage examples for android.content Intent hasExtra
public boolean hasExtra(String name)
From source file:Main.java
public static boolean hasScreenInfo(Intent intent) { return intent.hasExtra(SCREEN_ORDINAL); }
From source file:Main.java
public static boolean hasExtra(Intent intent, String key) { return intent.hasExtra(key); }
From source file:Main.java
/** * Whether a valid component to run the automation has been set. * /*from w ww. jav a 2s .com*/ * @param intent * @return */ public static final boolean isRunAutomationIntent(Intent intent) { return intent.hasExtra(EXTRA_RUN_AUTOMATION_COMPONENT); }
From source file:Main.java
private static Drawable getShortcutIcon(Context context, Intent shortcutIntent) { if (!shortcutIntent.hasExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)) { return null; }// w w w. j av a2s.c o m try { Intent.ShortcutIconResource iconRes = shortcutIntent .getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); Resources appRes = context.getPackageManager().getResourcesForApplication(iconRes.packageName); int resId = appRes.getIdentifier(iconRes.resourceName, null, null); return appRes.getDrawable(resId); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Checks if any extra is present in an intent. * * @param intent The intent to check.//w w w . j av a 2s .c o m * @param extras The extras to check for. * @return <code>true</code> if any checked extra is present, else <code>false</code>. */ public static boolean hasAny(Intent intent, String... extras) { for (String extra : extras) { if (intent.hasExtra(extra)) { return true; } } return false; }
From source file:Main.java
/** * Checks if all extras are present in an intent. * * @param intent The intent to check./*from w w w.j av a2 s. c om*/ * @param extras The extras to check for. * @return <code>true</code> if all extras are present, else <code>false</code>. */ public static boolean hasAll(Intent intent, String... extras) { for (String extra : extras) { if (!intent.hasExtra(extra)) { return false; } } return true; }
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); }/* www . ja v a 2 s .c o m*/ 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:Main.java
/** * Get string from extra or from metadata. * /*from w w w . ja va 2s .c om*/ * @param context * @param packagename * @param intent * @param extra * @param metadata * @return */ public static String getStringExtraOrMetadata(final Context context, final String packagename, final Intent intent, final String extra, final String metadata) { if (intent.hasExtra(extra) && intent.getStringExtra(extra) != null) { return intent.getStringExtra(extra); } else { //Try meta data of package Bundle md = null; try { md = context.getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } if (md != null && !TextUtils.isEmpty(md.getString(metadata))) { return md.getString(metadata); } else { return ""; } } }
From source file:Main.java
/** * Get resource ID from extra or from metadata. * /*from w w w. ja v a 2 s. co m*/ * @param context * @param packagename * @param intent * @param extra * @param metadata * @return */ public static int getResourceIdExtraOrMetadata(final Context context, final String packagename, final Intent intent, final String extra, final String metadata) { if (intent.hasExtra(extra) && intent.getStringExtra(extra) != null) { int id = 0; try { String resourcename = intent.getStringExtra(extra); Resources resources = context.getPackageManager().getResourcesForApplication(packagename); Log.i(TAG, "Looking up resource Id for " + resourcename); id = resources.getIdentifier(resourcename, "", packagename); } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } return id; } else { //Try meta data of package Bundle md = null; try { md = context.getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } if (md != null) { // Obtain resource ID and convert to resource name: int id = md.getInt(metadata); return id; } else { return 0; } } }
From source file:Main.java
/** * Get String array from Extra or from Meta-data through resources. * /* w w w . ja v a 2s . c om*/ * @param packagename * @param intent * @param extra * @param metadata */ public static String[] getStringArrayExtraOrMetadata(final Context context, final String packagename, final Intent intent, final String extra, final String metadata) { if (intent.hasExtra(extra) && intent.getStringArrayExtra(extra) != null) { return intent.getStringArrayExtra(extra); } else { //Try meta data of package Bundle md = null; try { md = context.getPackageManager().getApplicationInfo(packagename, PackageManager.GET_META_DATA).metaData; } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found", e); } if (md != null) { String[] array = null; try { int id = md.getInt(metadata); Resources resources = context.getPackageManager().getResourcesForApplication(packagename); array = resources.getStringArray(id); } catch (NameNotFoundException e) { Log.e(TAG, "Package name not found ", e); } catch (NumberFormatException e) { Log.e(TAG, "Metadata not valid id.", e); } catch (Resources.NotFoundException e) { Log.e(TAG, "Resource not found.", e); } if (array != null) { return array; } else { return null; } } else { return null; } } }