Java Code Examples for android.net.Uri#getAuthority()
The following examples show how to use
android.net.Uri#getAuthority() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Web3WebviewManager.java From react-native-web3-webview with MIT License | 5 votes |
private boolean shouldHandleURL(List<Pattern> originWhitelist, String url) { Uri uri = Uri.parse(url); String scheme = uri.getScheme() != null ? uri.getScheme() : ""; String authority = uri.getAuthority() != null ? uri.getAuthority() : ""; String urlToCheck = scheme + "://" + authority; for (Pattern pattern : originWhitelist) { if (pattern.matcher(urlToCheck).matches()) { return true; } } return false; }
Example 2
Source File: ContentResolver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Returns the content provider for the given content URI. * * @param uri The URI to a content provider * @return The ContentProvider for the given URI, or null if no content provider is found. * @hide */ public final IContentProvider acquireProvider(Uri uri) { if (!SCHEME_CONTENT.equals(uri.getScheme())) { return null; } final String auth = uri.getAuthority(); if (auth != null) { return acquireProvider(mContext, auth); } return null; }
Example 3
Source File: DefaultUriAdapter.java From weex-uikit with MIT License | 5 votes |
private Uri.Builder buildRelativeURI(Uri.Builder resultBuilder, Uri base, Uri uri) { if (uri.getAuthority() != null) { return resultBuilder.scheme(base.getScheme()); } else { resultBuilder .encodedAuthority(base.getEncodedAuthority()) .scheme(base.getScheme()) .path(null); if (uri.getPath().startsWith("/")) { //relative to root resultBuilder.appendEncodedPath(uri.getEncodedPath().substring(1)); } else { List<String> segments = base.getPathSegments(); //ignore last segment if not end with / int ignoreLast = 1; if (base.getPath().endsWith("/")) { ignoreLast = 0; } for (int i = 0, len = segments.size() - ignoreLast; i < len; i++) { resultBuilder.appendEncodedPath(segments.get(i)); } resultBuilder.appendEncodedPath(uri.getEncodedPath()); } return resultBuilder; } }
Example 4
Source File: ContentService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private String getUriSegment(Uri uri, int index) { if (uri != null) { if (index == 0) { return uri.getAuthority(); } else { return uri.getPathSegments().get(index - 1); } } else { return null; } }
Example 5
Source File: ContentService.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
private String getUriSegment(Uri uri, int index) { if (uri != null) { if (index == 0) { return uri.getAuthority(); } else { return uri.getPathSegments().get(index - 1); } } else { return null; } }
Example 6
Source File: WXWebComponent.java From CrazyDaily with Apache License 2.0 | 5 votes |
protected void createWebView() { String origin = null; try { String bundleUrl = WXSDKManager.getInstance().getSDKInstance(getInstanceId()).getBundleUrl(); Uri uri = Uri.parse(bundleUrl); String scheme = uri.getScheme(); String authority = uri.getAuthority(); if (!TextUtils.isEmpty(scheme) && !TextUtils.isEmpty(authority)) { origin = scheme + "://" + authority; } } catch (Exception e) { // do noting } mWebView = new WXWebView(getContext(), origin); }
Example 7
Source File: DocumentsApplication.java From FireFiles with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { final Uri data = intent.getData(); if (data != null) { final String authority = data.getAuthority(); mRoots.updateAuthorityAsync(authority); } else { mRoots.updateAsync(); } }
Example 8
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Returns the content provider for the given content URI. * * @param uri The URI to a content provider * @return The ContentProvider for the given URI, or null if no content provider is found. * @hide */ public final IContentProvider acquireUnstableProvider(Uri uri) { if (!SCHEME_CONTENT.equals(uri.getScheme())) { return null; } String auth = uri.getAuthority(); if (auth != null) { return acquireUnstableProvider(mContext, uri.getAuthority()); } return null; }
Example 9
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Returns the content provider for the given content URI if the process * already has a reference on it. * * @param uri The URI to a content provider * @return The ContentProvider for the given URI, or null if no content provider is found. * @hide */ public final IContentProvider acquireExistingProvider(Uri uri) { if (!SCHEME_CONTENT.equals(uri.getScheme())) { return null; } final String auth = uri.getAuthority(); if (auth != null) { return acquireExistingProvider(mContext, auth); } return null; }
Example 10
Source File: ActionService.java From opentasks with Apache License 2.0 | 5 votes |
@Override protected void onHandleWork(@NonNull Intent intent) { try { Uri instanceUri = intent.getData(); if (instanceUri == null || instanceUri.getAuthority() == null) { throw new RuntimeException(String.format("Invalid task instance Uri %s", instanceUri)); } ContentProviderClient contentProviderClient = getContentResolver().acquireContentProviderClient(instanceUri); for (RowSnapshot<TaskContract.Instances> snapshot : new QueryRowSet<>( new InstancesView<>(instanceUri.getAuthority(), contentProviderClient), new org.dmfs.android.contentpal.projections.Composite<>( Id.PROJECTION, EffectiveDueDate.PROJECTION, TaskStart.PROJECTION, TaskPin.PROJECTION, EffectiveTaskColor.PROJECTION, TaskTitle.PROJECTION, TaskVersion.PROJECTION, TaskIsClosed.PROJECTION), new EqArg<>(TaskContract.Instances._ID, ContentUris.parseId(instanceUri)))) { resolveAction(intent.getAction()).execute(this, contentProviderClient, snapshot.values(), instanceUri); } } catch (RuntimeException | RemoteException | OperationApplicationException e) { Log.e("ActionService", String.format("unable to execute action %s", intent.getAction()), e); } }
Example 11
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Resolves an android.resource URI to a {@link Resources} and a resource id. * * @hide */ public OpenResourceIdResult getResourceId(Uri uri) throws FileNotFoundException { String authority = uri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + uri); } else { try { r = mContext.getPackageManager().getResourcesForApplication(authority); } catch (NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + uri); } } List<String> path = uri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + uri); } int len = path.size(); int id; if (len == 1) { try { id = Integer.parseInt(path.get(0)); } catch (NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); } } else if (len == 2) { id = r.getIdentifier(path.get(1), path.get(0), authority); } else { throw new FileNotFoundException("More than two path segments: " + uri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + uri); } OpenResourceIdResult res = new OpenResourceIdResult(); res.r = r; res.id = id; return res; }
Example 12
Source File: SettingsProvider.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
@Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { /* * When a client attempts to openFile the default ringtone or * notification setting Uri, we will proxy the call to the current * default ringtone's Uri (if it is in the media provider). */ int ringtoneType = RingtoneManager.getDefaultType(uri); // Above call returns -1 if the Uri doesn't match a default type if (ringtoneType != -1) { Context context = getContext(); // Get the current value for the default sound Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context, ringtoneType); if (soundUri != null) { // Proxy the openFile call to media provider String authority = soundUri.getAuthority(); if (authority.equals(MediaStore.AUTHORITY)) { return context.getContentResolver().openFileDescriptor(soundUri, mode); } } } return super.openFile(uri, mode); }
Example 13
Source File: IconHelper.java From FireFiles with Apache License 2.0 | 5 votes |
/** * Load thumbnails for a directory list item. * @param uri The URI for the file being represented. * @param mimeType The mime type of the file being represented. * @param docFlags Flags for the file being represented. * @param iconThumb The itemview's thumbnail icon. * @param iconMimeBackground * @return */ public void loadThumbnail(Uri uri, String path, String mimeType, int docFlags, int docIcon, ImageView iconMime, ImageView iconThumb, View iconMimeBackground) { boolean cacheHit = false; final String docAuthority = uri.getAuthority(); String docId = DocumentsContract.getDocumentId(uri); final boolean supportsThumbnail = (docFlags & Document.FLAG_SUPPORTS_THUMBNAIL) != 0; final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mimeType); final boolean showThumbnail = supportsThumbnail && allowThumbnail && mThumbnailsEnabled; if (showThumbnail) { final Bitmap cachedResult = mCache.get(uri); if (cachedResult != null) { iconThumb.setImageBitmap(cachedResult); cacheHit = true; iconMimeBackground.setVisibility(View.GONE); } else { iconThumb.setImageDrawable(null); final LoaderTask task = new LoaderTask(uri, path, mimeType, mThumbSize, iconThumb, iconMime, iconMimeBackground); iconThumb.setTag(task); ProviderExecutor.forAuthority(docAuthority).execute(task); } } if (cacheHit) { iconMime.setImageDrawable(null); iconMime.setAlpha(0f); iconThumb.setAlpha(1f); } else { // Add a mime icon if the thumbnail is being loaded in the background. iconThumb.setImageDrawable(null); iconMime.setImageDrawable(getDocumentIcon(mContext, docAuthority, docId, mimeType, docIcon)); iconMime.setAlpha(1f); iconThumb.setAlpha(0f); } }
Example 14
Source File: SkiaImageRegionDecoder.java From BlogDemo with Apache License 2.0 | 4 votes |
@Override @NonNull public Point init(Context context, @NonNull Uri uri) throws Exception { String uriString = uri.toString(); if (uriString.startsWith(RESOURCE_PREFIX)) { Resources res; String packageName = uri.getAuthority(); if (context.getPackageName().equals(packageName)) { res = context.getResources(); } else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName); } int id = 0; List<String> segments = uri.getPathSegments(); int size = segments.size(); if (size == 2 && segments.get(0).equals("drawable")) { String resName = segments.get(1); id = res.getIdentifier(resName, "drawable", packageName); } else if (size == 1 && TextUtils.isDigitsOnly(segments.get(0))) { try { id = Integer.parseInt(segments.get(0)); } catch (NumberFormatException ignored) { } } decoder = BitmapRegionDecoder.newInstance(context.getResources().openRawResource(id), false); } else if (uriString.startsWith(ASSET_PREFIX)) { String assetName = uriString.substring(ASSET_PREFIX.length()); decoder = BitmapRegionDecoder.newInstance(context.getAssets().open(assetName, AssetManager.ACCESS_RANDOM), false); } else if (uriString.startsWith(FILE_PREFIX)) { decoder = BitmapRegionDecoder.newInstance(uriString.substring(FILE_PREFIX.length()), false); } else { InputStream inputStream = null; try { ContentResolver contentResolver = context.getContentResolver(); inputStream = contentResolver.openInputStream(uri); decoder = BitmapRegionDecoder.newInstance(inputStream, false); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { /* Ignore */ } } } } return new Point(decoder.getWidth(), decoder.getHeight()); }
Example 15
Source File: ImageGalleryUtils.java From droidddle with Apache License 2.0 | 4 votes |
public static String getFormattedImageUrl(@Nullable String url, int width, int height) { if (!TextUtils.isEmpty(url)) { Uri uri = Uri.parse(url); String scheme = uri.getScheme(); String authority = uri.getAuthority(); String path = uri.getEncodedPath(); Set<String> queryParameterNames = uri.getQueryParameterNames(); Uri.Builder builder = new Uri.Builder(); builder.scheme(scheme) .authority(authority) .appendPath(path.substring(1)); boolean isWidthSet = false; boolean isHeightSet = false; if (width > 2048) { width = 2048; } if (height > 2048) { height = 2048; } for (String key : queryParameterNames) { if (key.equals("w")) { builder.appendQueryParameter(key, String.valueOf(width)); isWidthSet = true; } else if (key.equals("h")) { builder.appendQueryParameter(key, String.valueOf(height)); isHeightSet = true; } else { builder.appendQueryParameter(key, uri.getQueryParameter(key)); } } if (!isWidthSet) { builder.appendQueryParameter("w", String.valueOf(width)); } if (!isHeightSet) { builder.appendQueryParameter("h", String.valueOf(height)); } String formattedUrl = String.format("http://xi.mg/%s", builder.build().toString()); formattedUrl = formattedUrl.replace(" ", "%20"); formattedUrl = formattedUrl.replace("%2520", "%20"); return formattedUrl; } return ""; }
Example 16
Source File: SkiaImageDecoder.java From PdfViewPager with Apache License 2.0 | 4 votes |
@Override @NonNull public Bitmap decode(Context context, @NonNull Uri uri) throws Exception { String uriString = uri.toString(); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap; options.inPreferredConfig = bitmapConfig; if (uriString.startsWith(RESOURCE_PREFIX)) { Resources res; String packageName = uri.getAuthority(); if (context.getPackageName().equals(packageName)) { res = context.getResources(); } else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName); } int id = 0; List<String> segments = uri.getPathSegments(); int size = segments.size(); if (size == 2 && segments.get(0).equals("drawable")) { String resName = segments.get(1); id = res.getIdentifier(resName, "drawable", packageName); } else if (size == 1 && TextUtils.isDigitsOnly(segments.get(0))) { try { id = Integer.parseInt(segments.get(0)); } catch (NumberFormatException ignored) { } } bitmap = BitmapFactory.decodeResource(context.getResources(), id, options); } else if (uriString.startsWith(ASSET_PREFIX)) { String assetName = uriString.substring(ASSET_PREFIX.length()); bitmap = BitmapFactory.decodeStream(context.getAssets().open(assetName), null, options); } else if (uriString.startsWith(FILE_PREFIX)) { bitmap = BitmapFactory.decodeFile(uriString.substring(FILE_PREFIX.length()), options); } else { InputStream inputStream = null; try { ContentResolver contentResolver = context.getContentResolver(); inputStream = contentResolver.openInputStream(uri); bitmap = BitmapFactory.decodeStream(inputStream, null, options); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { /* Ignore */ } } } } if (bitmap == null) { throw new RuntimeException( "Skia image region decoder returned null bitmap - image format may not be supported" ); } return bitmap; }
Example 17
Source File: SkiaImageRegionDecoder.java From imsdk-android with MIT License | 4 votes |
@Override @NonNull public Point init(Context context, @NonNull Uri uri) throws Exception { String uriString = uri.toString(); if (uriString.startsWith(RESOURCE_PREFIX)) { Resources res; String packageName = uri.getAuthority(); if (context.getPackageName().equals(packageName)) { res = context.getResources(); } else { PackageManager pm = context.getPackageManager(); res = pm.getResourcesForApplication(packageName); } int id = 0; List<String> segments = uri.getPathSegments(); int size = segments.size(); if (size == 2 && segments.get(0).equals("drawable")) { String resName = segments.get(1); id = res.getIdentifier(resName, "drawable", packageName); } else if (size == 1 && TextUtils.isDigitsOnly(segments.get(0))) { try { id = Integer.parseInt(segments.get(0)); } catch (NumberFormatException ignored) { } } decoder = BitmapRegionDecoder.newInstance(context.getResources().openRawResource(id), false); } else if (uriString.startsWith(ASSET_PREFIX)) { String assetName = uriString.substring(ASSET_PREFIX.length()); decoder = BitmapRegionDecoder.newInstance(context.getAssets().open(assetName, AssetManager.ACCESS_RANDOM), false); } else if (uriString.startsWith(FILE_PREFIX)) { decoder = BitmapRegionDecoder.newInstance(uriString.substring(FILE_PREFIX.length()), false); } else { InputStream inputStream = null; try { ContentResolver contentResolver = context.getContentResolver(); inputStream = contentResolver.openInputStream(uri); decoder = BitmapRegionDecoder.newInstance(inputStream, false); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { /* Ignore */ } } } } return new Point(decoder.getWidth(), decoder.getHeight()); }
Example 18
Source File: Urls.java From Floo with Apache License 2.0 | 4 votes |
@NonNull public static String indexUrl(@NonNull final Uri uri) { return uri.getScheme() != null && uri.getAuthority() != null ? uri.getAuthority() + uri.getPath() : uri.getPath(); }
Example 19
Source File: DataItemInternal.java From android_packages_apps_GmsCore with Apache License 2.0 | 4 votes |
public DataItemInternal(Uri uri) { this.uri = uri; this.host = uri.getAuthority(); this.path = uri.getPath(); }
Example 20
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 3 votes |
/** * Like {@link #acquireContentProviderClient(Uri)}, but for use when you do * not trust the stability of the target content provider. This turns off * the mechanism in the platform clean up processes that are dependent on * a content provider if that content provider's process goes away. Normally * you can safely assume that once you have acquired a provider, you can freely * use it as needed and it won't disappear, even if your process is in the * background. If using this method, you need to take care to deal with any * failures when communicating with the provider, and be sure to close it * so that it can be re-opened later. In particular, catching a * {@link android.os.DeadObjectException} from the calls there will let you * know that the content provider has gone away; at that point the current * ContentProviderClient object is invalid, and you should release it. You * can acquire a new one if you would like to try to restart the provider * and perform new operations on it. */ public final @Nullable ContentProviderClient acquireUnstableContentProviderClient( @NonNull Uri uri) { Preconditions.checkNotNull(uri, "uri"); IContentProvider provider = acquireUnstableProvider(uri); if (provider != null) { return new ContentProviderClient(this, provider, uri.getAuthority(), false); } return null; }