List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:Main.java
/** * For Activities which want to treat new Intents as Intents with a new Tag attached. If the given Intent has a Tag extra, the {@link #mTag} and * {@link #mUID} will be updated and a Toast message will be shown in the calling Context (Activity). This method will also check if the * device/tag supports Mifare Classic (see return values). * //from w w w . ja v a 2 s .c o m * @param intent The Intent which should be checked for a new Tag. * @param context The Context in which the Toast will be shown. * @return <ul> * <li>1 - The device/tag supports Mifare Classic</li> * <li>0 - The device/tag does not support Mifare Classic</li> * <li>-1 - Wrong Intent (action is not "ACTION_TECH_DISCOVERED").</li> * </ul> * @see #mTag * @see #mUID */ public static int treatAsNewTag(Intent intent, Context context) { // Check if Intent has a NFC Tag. if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(intent.getAction())) { Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); mTag = tag; mUID = tag.getId(); // Show Toast message with UID. // String id = " (UID: "; // id += byte2HexString(tag.getId()); // id += ")"; // Toast.makeText(context, id, Toast.LENGTH_LONG).show(); // Return "1" if device supports Mifare Classic. "0" otherwise. return (Arrays.asList(tag.getTechList()).contains(MifareClassic.class.getName())) ? 1 : 0; } return -1; }
From source file:Main.java
private static Intent resolveIntent(Context context, Intent i) { ResolveInfo result = context.getPackageManager().resolveActivity(i, 0); return result != null ? new Intent(i.getAction()).setClassName(result.activityInfo.packageName, result.activityInfo.name) : null;/*www .ja v a2s. co m*/ }
From source file:Main.java
public static Uri handleChoosenImage(Intent data, Uri fileUri) { final boolean isCamera; if (data == null) { isCamera = true;//from w w w . jav a2 s.com } else { final String action = data.getAction(); if (action == null) { isCamera = false; } else { isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); } } Uri selectedImageUri; if (isCamera) { selectedImageUri = fileUri; } else { selectedImageUri = data == null ? null : data.getData(); } return selectedImageUri; }
From source file:Main.java
/** * Converts an {@link android.content.Intent} object to a {@code String}. * * @param intent The converted intent.//from w w w.j a v a 2 s. c o m * @return The string representation of the intent. */ @SuppressWarnings("PMD.ConsecutiveLiteralAppends") @NonNull public static String toString(@Nullable final Intent intent) { if (intent == null) { return "null"; } final StringBuilder stringBuilder = new StringBuilder("Intent{action=\"").append(intent.getAction()) .append('"').append(ITEM_DIVIDER).append("data=\"").append(intent.getDataString()).append('"') .append(ITEM_DIVIDER).append("component=\"").append(intent.getComponent()).append('"') .append(ITEM_DIVIDER); final Bundle extras = intent.getExtras(); stringBuilder.append("extras=").append(extras == null ? null : toString(extras)).append('}'); return stringBuilder.toString(); }
From source file:Main.java
public static Uri getfinalUriForCameraOrOtherImages(Intent data, Uri mOutputFileUri) { final boolean isCamera; Uri selectedImageUri = null;// w w w . j av a2 s .c o m if (data == null || data.getData() == null) { isCamera = true; } else { final String action = data.getAction(); if (action == null) { isCamera = false; } else { isCamera = action.equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); } } if (isCamera) { selectedImageUri = mOutputFileUri; } else { selectedImageUri = data == null ? null : data.getData(); } return selectedImageUri; }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }/*from w w w. j av a2 s . co m*/ LauncherAppState app = LauncherAppState.getInstance(); return app.getModel().infoFromShortcutIntent(context, data, null); }
From source file:com.android.launcher4.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }/*from w w w .j av a2 s. c om*/ LauncherAppState app = LauncherAppState.getInstance(); ShortcutInfo info = app.getModel().infoFromShortcutIntent(context, data, null); info.title = ensureValidName(context, launchIntent, info.title); return info; }
From source file:androidx.media.session.MediaButtonReceiver.java
/** * Extracts any available {@link KeyEvent} from an {@link Intent#ACTION_MEDIA_BUTTON} * intent, passing it onto the {@link MediaSessionCompat} using * {@link MediaControllerCompat#dispatchMediaButtonEvent(KeyEvent)}, which in turn * will trigger callbacks to the {@link MediaSessionCompat.Callback} registered via * {@link MediaSessionCompat#setCallback(MediaSessionCompat.Callback)}. * @param mediaSessionCompat A {@link MediaSessionCompat} that has a * {@link MediaSessionCompat.Callback} set. * @param intent The intent to parse./*from w ww. ja v a 2 s . c o m*/ * @return The extracted {@link KeyEvent} if found, or null. */ public static KeyEvent handleIntent(MediaSessionCompat mediaSessionCompat, Intent intent) { if (mediaSessionCompat == null || intent == null || !Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction()) || !intent.hasExtra(Intent.EXTRA_KEY_EVENT)) { return null; } KeyEvent ke = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); MediaControllerCompat mediaController = mediaSessionCompat.getController(); mediaController.dispatchMediaButtonEvent(ke); return ke; }
From source file:Main.java
private static List<Intent> addIntentsToList(Context context, List<Intent> list, Intent intent) { List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(intent, 0); for (ResolveInfo resolveInfo : resInfo) { String packageName = resolveInfo.activityInfo.packageName; Intent targetedIntent = new Intent(intent); targetedIntent.setPackage(packageName); list.add(targetedIntent);//w w w . ja va 2 s . c om Log.d(TAG, "Intent: " + intent.getAction() + " package: " + packageName); } return list; }
From source file:at.wada811.utils.IntentUtils.java
public static String dump(Intent intent) throws JSONException { JSONObject json = new JSONObject(); json.put("action", intent.getAction()); if (intent.getCategories() != null) { JSONArray categories = new JSONArray(); for (String category : intent.getCategories()) { categories.put(category);// ww w. jav a 2 s .c o m } json.put("category", categories); } json.put("type", intent.getType()); Bundle bundle = intent.getExtras(); if (bundle != null) { JSONObject extras = new JSONObject(); for (String key : bundle.keySet()) { extras.put(key, bundle.get(key)); } json.put("extras", extras); } return json.toString(4); }