List of usage examples for android.content ContentResolver SCHEME_CONTENT
String SCHEME_CONTENT
To view the source code for android.content ContentResolver SCHEME_CONTENT.
Click Source Link
From source file:Main.java
public static boolean isMediaStoreUri(Uri uri) { return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && MediaStore.AUTHORITY.equals(uri.getAuthority()); }
From source file:Main.java
/** @see http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue */ public static int getSampleSize(Context context, Uri uri, float maxSize) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//ww w.j av a 2 s . co m if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { try { InputStream stream = context.getContentResolver().openInputStream(uri); BitmapFactory.decodeStream(stream, null, options); stream.close(); } catch (Exception e) { e.printStackTrace(); } } else BitmapFactory.decodeFile(uri.getPath(), options); int longSide = Math.max(options.outHeight, options.outWidth); return getSampleSize(longSide, maxSize); }
From source file:Main.java
public static String getRealFilePath(Context context, Uri uri) { if (null == uri) return null; String scheme = uri.getScheme(); String data = null;/*from w w w . j av a 2 s. c om*/ if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
/** * Try to return the absolute file path from the given Uri * //from ww w . j a va 2 s . c om * @param context * @param uri * @return the file path or null */ public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null; if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
public static String getRealFilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null;// w ww. j a va 2 s. c om if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
/** * Return an {@link InputStream} from the given uri. ( can be a local content, a file path or an http url ) * //from ww w . j a v a 2 s . c o m * @param context * @param uri * @return the {@link InputStream} from the given uri, null if uri cannot be opened */ public static InputStream openInputStream(Context context, Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); InputStream stream = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { // from file stream = openFileInputStream(uri.getPath()); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { // from content stream = openContentInputStream(context, uri); } else if ("http".equals(scheme) || "https".equals(scheme)) { // from remote uri stream = openRemoteInputStream(uri); } return stream; }
From source file:Main.java
/** * Acquires input stream for the image resource identified by uri. * * This is a long-running I/O operation that must run in a background thread. * * @param context//from ww w. j a v a2 s. co m * @param uri * @return * @throws IOException */ public static InputStream getInputStream(Context context, Uri uri) throws IOException { if (uri.getScheme().contentEquals(ContentResolver.SCHEME_CONTENT)) { return context.getContentResolver().openInputStream(uri); } else { return (InputStream) new URL(uri.toString()).getContent(); } }
From source file:Main.java
/** * Try to return the absolute file path from the given Uri * * @param context//from ww w. j a v a 2s . com * @param uri * @return the file path or null */ public static String uri2FilePath(final Context context, final Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); String data = null; if (scheme == null) data = uri.getPath(); else if (ContentResolver.SCHEME_FILE.equals(scheme)) { data = uri.getPath(); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); if (null != cursor) { if (cursor.moveToFirst()) { int index = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); if (index > -1) { data = cursor.getString(index); } } cursor.close(); } } return data; }
From source file:Main.java
/** * Return an {@link InputStream} from the given uri. ( can be a local * content, a file path or an http url ) * * @param context// w ww. j ava 2 s . c o m * @param uri * @return the {@link InputStream} from the given uri, null if uri cannot be * opened */ public static InputStream openInputStream(Context context, Uri uri) { if (null == uri) return null; final String scheme = uri.getScheme(); InputStream stream = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { // from file stream = openFileInputStream(uri.getPath()); } else if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { // from content stream = openContentInputStream(context, uri); } return stream; }
From source file:Main.java
public static InputStream openStreamForUri(Context context, Uri uri) throws IOException { switch (uri.getScheme()) { case ContentResolver.SCHEME_CONTENT: case ContentResolver.SCHEME_ANDROID_RESOURCE: try {//from w ww . j av a 2 s. c o m return context.getContentResolver().openInputStream(uri); } catch (RuntimeException ignore) { } case "file": case "http": case "https": return new URL(uri.toString()).openStream(); } throw new IOException("Unable to open " + uri.toString()); }