/** * @param uri * The Uri to check. * * @return Whether the Uri authority is ExternalStorageProvider. */ public static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); }
/** * @param uri * The Uri to check. * * @return Whether the Uri authority is Google Photos. */ public static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); } }
/** * @param uri The Uri to check. * @return Whether the Uri authority is ExternalStorageProvider. * @author paulburke */ public static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is Google Photos. */ public static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); }
/** * @param uri * The Uri to check. * * @return Whether the Uri authority is DownloadsProvider. */ public static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); }
/** * @param uri * The Uri to check. * * @return Whether the Uri authority is MediaProvider. */ public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); }
public static boolean isMediaStoreUri(Uri uri) { return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && MediaStore.AUTHORITY.equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is MediaProvider. * @author paulburke */ public static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is DownloadsProvider. * @author paulburke */ public static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is ExternalStorageProvider. */ static boolean isExternalStorageDocument(Uri uri) { return "com.android.externalstorage.documents".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is Google Photos. */ static boolean isGooglePhotosUri(Uri uri) { return "com.google.android.apps.photos.content".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is DownloadsProvider. */ static boolean isDownloadsDocument(Uri uri) { return "com.android.providers.downloads.documents".equals(uri.getAuthority()); }
/** * @param uri The Uri to check. * @return Whether the Uri authority is MediaProvider. */ static boolean isMediaDocument(Uri uri) { return "com.android.providers.media.documents".equals(uri.getAuthority()); }
@Override public boolean canHandleRequest(@NonNull Request data) { final Uri uri = data.uri; return uri != null && SCHEME_CONTENT.equals(uri.getScheme()) && MediaStore.AUTHORITY.equals(uri.getAuthority()); }
public boolean matches(Uri test) { if (!Objects.equals(uri.getScheme(), test.getScheme())) { return false; } if (!Objects.equals(uri.getAuthority(), test.getAuthority())) { return false; } String uriPath = uri.getPath(); String testPath = test.getPath(); return Objects.equals(uriPath, testPath) || (notifyForDescendents && testPath != null && testPath.startsWith(uriPath)); } }
@DrawableRes private int findResourceIdFromTypeAndNameResourceUri(Context context, Uri source) { List<String> segments = source.getPathSegments(); String packageName = source.getAuthority(); String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX); String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX); int result = context.getResources().getIdentifier(resourceName, typeName, packageName); if (result == MISSING_RESOURCE_ID) { result = Resources.getSystem().getIdentifier(resourceName, typeName, ANDROID_PACKAGE_NAME); } if (result == MISSING_RESOURCE_ID) { throw new IllegalArgumentException("Failed to find resource id for: " + source); } return result; }
static Resources getResources(Context context, Request data) throws FileNotFoundException { if (data.resourceId != 0 || data.uri == null) { return context.getResources(); } String pkg = data.uri.getAuthority(); if (pkg == null) throw new FileNotFoundException("No package provided: " + data.uri); try { PackageManager pm = context.getPackageManager(); return pm.getResourcesForApplication(pkg); } catch (PackageManager.NameNotFoundException e) { throw new FileNotFoundException("Unable to obtain resources for package: " + data.uri); } }
public static ContentProvider getProvider(Uri uri) { if (uri == null || !ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) { return null; } return getProvider(uri.getAuthority()); }
@Nullable @Override public Resource<Drawable> decode(@NonNull Uri source, int width, int height, @NonNull Options options) { String packageName = source.getAuthority(); Context targetContext = findContextForPackage(source, packageName); @DrawableRes int resId = findResourceIdFromUri(targetContext, source); // We can't get a theme from another application. Drawable drawable = DrawableDecoderCompat.getDrawable(context, targetContext, resId); return NonOwnedDrawableResource.newInstance(drawable); }
@Test public void shouldParseUris() throws Exception { Uri testUri = Uri.parse("http://someplace.com:8080/a/path?param=value&another_param=another_value#top"); assertThat(testUri.getQuery()).isEqualTo("param=value&another_param=another_value"); assertThat(testUri.getPort()).isEqualTo(8080); assertThat(testUri.getAuthority()).isEqualTo("someplace.com:8080"); assertThat(testUri.getHost()).isEqualTo("someplace.com"); assertThat(testUri.getFragment()).isEqualTo("top"); assertThat(testUri.getPath()).isEqualTo("/a/path"); assertThat(testUri.getScheme()).isEqualTo("http"); }