List of usage examples for android.content Intent getData
public @Nullable Uri getData()
From source file:Main.java
public static Uri getfinalUriForCameraOrOtherImages(Intent data, Uri mOutputFileUri) { final boolean isCamera; Uri selectedImageUri = null;//from w w w.ja v a 2s . c om 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:Main.java
public static Uri getImageUri(Intent data) throws Exception { Uri imageUri;/*w w w . java 2 s. c o m*/ if (data == null) { imageUri = lastCameraImageSaved; } else { imageUri = data.getData(); } return imageUri; }
From source file:Main.java
public static List<String> listAlldir(Context cxt) { Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Uri uri = intent.getData(); List<String> list = new ArrayList<String>(); String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = cxt.getContentResolver().query(uri, proj, null, null, null); while (cursor.moveToNext()) { String path = cursor.getString(0); list.add(new File(path).getAbsolutePath()); }//from www.j ava 2 s. c o m return list; }
From source file:Main.java
/** * Inverse operation of {@link #fragmentArgumentsToIntent(Bundle)}. *///from w ww . j a v a 2 s . c om public static Bundle intentToFragmentArguments(Intent intent) { Bundle arguments = new Bundle(); if (intent == null) { return arguments; } final Uri data = intent.getData(); if (data != null) { arguments.putParcelable(URI_KEY, data); } final Bundle extras = intent.getExtras(); if (extras != null) { arguments.putAll(extras); } return arguments; }
From source file:Main.java
/** * Converts an intent into a {@link Bundle} suitable for use as fragment * arguments./* w ww . j av a 2 s . c o m*/ */ public static Bundle intentToFragmentArguments(Intent intent) { Bundle arguments = new Bundle(); if (intent == null) { return arguments; } final Uri data = intent.getData(); if (data != null) { arguments.putParcelable("_uri", data); } final Bundle extras = intent.getExtras(); if (extras != null) { arguments.putAll(intent.getExtras()); } return arguments; }
From source file:Main.java
public static final HashMap<String, String> getAllRawQueryParameters(Intent intent) { HashMap<String, String> queries = new HashMap<String, String>(); if (intent != null) { Uri uri = intent.getData(); if (null != uri) { final String query = uri.getEncodedQuery(); if (query != null) { final int length = query.length(); int start = 0; do { int nextAmpersand = query.indexOf('&', start); int end = nextAmpersand != -1 ? nextAmpersand : length; int separator = query.indexOf('=', start); if (separator > end || separator == -1) { separator = end; }// w w w. jav a2 s . com String encodedKey = query.substring(start, separator); String encodedValue = query.substring(separator + 1, end); String key = Uri.decode(encodedKey); if (!queries.containsKey(key)) { queries.put(key, encodedValue); } // Move start to end of name. if (nextAmpersand != -1) { start = nextAmpersand + 1; } else { break; } } while (true); } } } return queries; }
From source file:Main.java
/** * @param context/* w w w . j ava 2s. co m*/ * @param data * @return */ @Nullable public static byte[] retrieveSelectedImage(@NonNull Context context, @NonNull Intent data) { InputStream inStream = null; Bitmap bitmap = null; try { inStream = context.getContentResolver().openInputStream(data.getData()); bitmap = BitmapFactory.decodeStream(inStream); final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream); return outStream.toByteArray(); } catch (FileNotFoundException e) { return null; } finally { if (inStream != null) { try { inStream.close(); } catch (IOException ignored) { } } if (bitmap != null) { bitmap.recycle(); } } }
From source file:Main.java
public static String UriToPath(Context context, Intent data) { if (data == null) { return null; }/*w w w . j ava 2s. com*/ Uri photoUri = data.getData(); if (photoUri == null) { return null; } return getPath(context, photoUri); }
From source file:Main.java
/** * Returns import source uri based on the Intent. *///from w w w . ja va2 s .c om static Uri getImportUri(Intent intent) { String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action)) { return intent.getParcelableExtra(Intent.EXTRA_STREAM); } if (Intent.ACTION_VIEW.equals(action)) { return intent.getData(); } return null; }
From source file:com.allen.mediautil.ImageTakerHelper.java
/** * ?/*from www .j a v a2 s .c om*/ * * @param data * @return ? */ public static String readBitmapFromAlbumResult(Context context, Intent data) { Uri imageUri = data.getData(); if (imageUri == null) { return null; } else if (imageUri.toString().startsWith("file:///")) { try { // ?? BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(imageUri.getPath(), options); return imageUri.getPath(); } catch (Exception ex) { Toast.makeText(context.getApplicationContext(), "?", Toast.LENGTH_SHORT).show(); return null; } } else { String[] projection = { MediaStore.MediaColumns.DATA }; CursorLoader cursorLoader = new CursorLoader(context, imageUri, projection, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); cursor.moveToFirst(); String selectedImagePath = cursor.getString(column_index); cursor.close(); return selectedImagePath; } }