List of usage examples for android.net Uri getScheme
@Nullable public abstract String getScheme();
From source file:de.k3b.android.toGoZip.SettingsImpl.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static DocumentFile getDocFile(Context context, @NonNull String dir) { DocumentFile docDir = null;/*from w w w .j a v a 2 s . c o m*/ if (dir.indexOf(":") >= 0) { Uri uri = Uri.parse(dir); if ("file".equals(uri.getScheme())) { File fileDir = new File(uri.getPath()); docDir = DocumentFile.fromFile(fileDir); } else { docDir = DocumentFile.fromTreeUri(context, uri); } } else { docDir = DocumentFile.fromFile(new File(dir)); } return docDir; }
From source file:com.commonsware.android.diceware.PassphraseFragment.java
private static DocumentFileCompat buildDocFileForUri(Context ctxt, Uri document) { DocumentFileCompat docFile;// www . j a va2 s. com if (document.getScheme().equals(ContentResolver.SCHEME_CONTENT)) { docFile = DocumentFileCompat.fromSingleUri(ctxt, document); } else { docFile = DocumentFileCompat.fromFile(new File(document.getPath())); } return (docFile); }
From source file:net.wequick.small.Small.java
public static void openUri(Uri uri, Context context) { // System url schemes String scheme = uri.getScheme(); if (scheme != null && !scheme.equals("http") && !scheme.equals("https") && !scheme.equals("file") && ApplicationUtils.canOpenUri(uri, context)) { ApplicationUtils.openUri(uri, context); return;/* www . j a va2s. c o m*/ } // Small url schemes Bundle bundle = Bundle.getLaunchableBundle(uri); if (bundle != null) { bundle.launchFrom(context); } }
From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java
public static String getName(Context context, Uri uri) { if (uri == null || uri.equals(Uri.EMPTY)) return ""; String fileName = ""; try {/*from w ww.j av a 2 s . com*/ String scheme = uri.getScheme(); if (scheme.equals("file")) { fileName = uri.getLastPathSegment(); } else if (scheme.equals("content")) { String[] proj = { MediaStore.Images.Media.DISPLAY_NAME }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor != null && cursor.getCount() != 0) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME); cursor.moveToFirst(); fileName = cursor.getString(columnIndex); } if (cursor != null) { cursor.close(); } } } catch (Exception ex) { return ""; } return fileName; }
From source file:com.androidzeitgeist.dashwatch.common.IOUtil.java
public static String getCacheFilenameForUri(Uri uri) { StringBuilder filename = new StringBuilder(); filename.append(uri.getScheme()).append("_").append(uri.getHost()).append("_"); String encodedPath = uri.getEncodedPath(); if (!TextUtils.isEmpty(encodedPath)) { int length = encodedPath.length(); if (length > 60) { encodedPath = encodedPath.substring(length - 60); }//from w w w .j a v a 2 s . c o m encodedPath = encodedPath.replace('/', '_'); filename.append(encodedPath).append("_"); } try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(uri.toString().getBytes("UTF-8")); byte[] digest = md.digest(); for (byte b : digest) { if ((0xff & b) < 0x10) { filename.append("0").append(Integer.toHexString((0xFF & b))); } else { filename.append(Integer.toHexString(0xFF & b)); } } } catch (NoSuchAlgorithmException e) { filename.append(uri.toString().hashCode()); } catch (UnsupportedEncodingException e) { filename.append(uri.toString().hashCode()); } return filename.toString(); }
From source file:com.android.emailcommon.utility.AttachmentUtilities.java
/** * @return mime-type for a {@link Uri}.// ww w . j ava 2 s. com * - Use {@link ContentResolver#getType} for a content: URI. * - Use {@link #inferMimeType} for a file: URI. * - Otherwise returns null. */ public static String inferMimeTypeForUri(Context context, Uri uri) { final String scheme = uri.getScheme(); if (ContentResolver.SCHEME_CONTENT.equals(scheme)) { return context.getContentResolver().getType(uri); } else if (ContentResolver.SCHEME_FILE.equals(scheme)) { return inferMimeType(uri.getLastPathSegment(), ""); } else { Log.e(Logging.LOG_TAG, "Unable to determine MIME type for uri=" + uri, new Error()); return null; } }
From source file:mobisocial.noteshere.util.UriImage.java
public static float rotationForImage(Context context, Uri uri) { if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); try {/* w w w . java 2 s. c om*/ if (c.moveToFirst()) { return c.getInt(0); } } finally { c.close(); } } else if (uri.getScheme().equals("file")) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int) exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; }
From source file:com.duy.pascal.ui.file.FileManager.java
/** * get path from uri/* w w w. j av a 2 s .c om*/ */ @Nullable public static String getPathFromUri(Context context, Uri uri) throws URISyntaxException { if ("content".equalsIgnoreCase(uri.getScheme())) { String[] projection = { "_data" }; Cursor cursor; try { cursor = context.getContentResolver().query(uri, projection, null, null, null); if (cursor == null) { return null; } int index = cursor.getColumnIndexOrThrow("_data"); if (cursor.moveToFirst()) { String path = cursor.getString(index); cursor.close(); return path; } } catch (Exception e) { e.printStackTrace(); } } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } return null; }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
@NonNull public static DocumentFile getDocumentFile(@NonNull Context context, @NonNull Uri uri) { DocumentFile df = null;/*from w w w .jav a 2 s. c o m*/ if (FILE_SCHEME.equals(uri.getScheme())) { df = DocumentFile.fromFile(new File(uri.getPath())); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && SAF_SCHEME.equals(uri.getScheme()) && SAF_AUTHORITY.equals(uri.getAuthority())) { if (DocumentsContract.isDocumentUri(context, uri)) { df = DocumentFile.fromSingleUri(context, uri); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && DocumentsContract.isTreeUri(uri)) { df = DocumentFile.fromTreeUri(context, uri); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // Best guess is that it's a tree... df = DocumentFile.fromTreeUri(context, uri); } } if (df == null) { throw new IllegalArgumentException("Invalid URI: " + uri); } return df; }
From source file:com.vokal.async_image_cache.ImageWorker.java
protected static boolean isLocalUri(final Uri aUri) { return !aUri.getScheme().equals("http") && !aUri.getScheme().equals("https"); }