本文整理匯總了Java中android.net.Uri.getAuthority方法的典型用法代碼示例。如果您正苦於以下問題:Java Uri.getAuthority方法的具體用法?Java Uri.getAuthority怎麽用?Java Uri.getAuthority使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.Uri
的用法示例。
在下文中一共展示了Uri.getAuthority方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadResourceIdFromUri
import android.net.Uri; //導入方法依賴的package包/類
@DrawableRes
private int loadResourceIdFromUri(Uri source) {
List<String> segments = source.getPathSegments();
@DrawableRes Integer result = null;
if (segments.size() == NAME_URI_PATH_SEGMENTS) {
String packageName = source.getAuthority();
String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX);
String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX);
result = context.getResources().getIdentifier(resourceName, typeName, packageName);
} else if (segments.size() == ID_PATH_SEGMENTS) {
try {
result = Integer.valueOf(segments.get(RESOURCE_ID_SEGMENT_INDEX));
} catch (NumberFormatException e) {
// Ignored.
}
}
if (result == null) {
throw new IllegalArgumentException("Unrecognized Uri format: " + source);
} else if (result == 0) {
throw new IllegalArgumentException("Failed to obtain resource id for: " + source);
}
return result;
}
示例2: loadThumbnail
import android.net.Uri; //導入方法依賴的package包/類
/**
* 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);
}
}
示例3: beforeInvoke
import android.net.Uri; //導入方法依賴的package包/類
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
if (args != null) {
final int index = 1;
if (args.length > index && args[index] instanceof Uri) {
Uri uri = (Uri) args[index];
String authority = uri.getAuthority();
ProviderInfo provider = PluginManager.getInstance().resolveContentProvider(authority, 0);
if (provider != null) {
ProviderInfo info = PluginManager.getInstance().selectStubProviderInfo(authority);
Uri.Builder newUri = new Uri.Builder();
newUri.scheme("content");
newUri.authority(uri.getAuthority());
newUri.path(uri.getPath());
newUri.query(uri.getQuery());
newUri.appendQueryParameter(Env.EXTRA_TARGET_AUTHORITY,authority);
args[index] = newUri.build();
// return true;
} else {
Log.w(TAG, "getContentProvider,fake fail 2=%s", authority);
}
}
}
return super.beforeInvoke(receiver, method, args);
}
示例4: parseSharePath
import android.net.Uri; //導入方法依賴的package包/類
private String[] parseSharePath() {
final String path = mSharePathEditText.getText().toString();
if (path.startsWith("\\")) {
// Possibly Windows share path
if (path.length() == 1) {
return null;
}
final int endCharacter = path.endsWith("\\") ? path.length() - 1 : path.length();
final String[] components = path.substring(2, endCharacter).split("\\\\");
return components.length == 2 ? components : null;
} else {
// Try SMB URI
final Uri smbUri = Uri.parse(path);
final String host = smbUri.getAuthority();
if (TextUtils.isEmpty(host)) {
return null;
}
final List<String> pathSegments = smbUri.getPathSegments();
if (pathSegments.size() != 1) {
return null;
}
final String share = pathSegments.get(0);
return new String[] { host, share };
}
}
示例5: testJobRescheduledPassesUriAuthorityForward
import android.net.Uri; //導入方法依賴的package包/類
@Test
public void testJobRescheduledPassesUriAuthorityForward() {
Uri changedUri = job.getTriggerContentUris()[0].getUri();
String changedAuthority = changedUri.getAuthority();
JobStatus failedJobStatus = new JobStatus(job, AlarmScheduler.TAG, 0, 0);
failedJobStatus.changedUris = Collections.singleton(changedUri);
failedJobStatus.changedAuthorities = Collections.singleton(changedAuthority);
JobStatus newJobStatus = new JobStatus(job, AlarmScheduler.TAG, 0, 0);
scheduler.onJobRescheduled(newJobStatus, failedJobStatus);
assertThat(newJobStatus.changedUris, hasItem(changedUri));
assertThat(newJobStatus.changedAuthorities, hasItem(changedAuthority));
}
示例6: Attachment
import android.net.Uri; //導入方法依賴的package包/類
private Attachment(UUID callId, Bitmap bitmap, Uri uri) {
this.callId = callId;
this.bitmap = bitmap;
this.originalUri = uri;
if (uri != null) {
String scheme = uri.getScheme();
if ("content".equalsIgnoreCase(scheme)) {
isContentUri = true;
shouldCreateFile = uri.getAuthority() != null &&
!uri.getAuthority().startsWith("media");
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
shouldCreateFile = true;
} else if (!Utility.isWebUri(uri)) {
throw new FacebookException("Unsupported scheme for media Uri : " + scheme);
}
} else if (bitmap != null) {
shouldCreateFile = true;
} else {
throw new FacebookException("Cannot share media without a bitmap or Uri set");
}
attachmentName = !shouldCreateFile ? null : UUID.randomUUID().toString();
attachmentUrl = !shouldCreateFile
? this.originalUri.toString()
: FacebookContentProvider.getAttachmentUrl(
FacebookSdk.getApplicationId(),
callId,
attachmentName);
}
示例7: getTheDrawable
import android.net.Uri; //導入方法依賴的package包/類
public Drawable getTheDrawable(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);
}
return r.getDrawable(id);
}
示例8: onReceive
import android.net.Uri; //導入方法依賴的package包/類
@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();
}
}
示例9: buildRelativeURI
import android.net.Uri; //導入方法依賴的package包/類
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;
}
}
示例10: getFromUri
import android.net.Uri; //導入方法依賴的package包/類
public static Repo getFromUri(Context context, String uriString) {
Uri uri = Uri.parse(uriString);
if (uri != null && uri.getScheme() != null) { // Make sure uri is valid and has a scheme
try {
switch (uri.getScheme()) {
case ContentRepo.SCHEME:
return new ContentRepo(context, uri);
case DropboxRepo.SCHEME:
if (! BuildConfig.IS_DROPBOX_ENABLED) {
return null;
}
/* There should be no authority. */
if (uri.getAuthority() != null) {
return null;
}
return new DropboxRepo(context, uri);
case DirectoryRepo.SCHEME:
return new DirectoryRepo(uriString, false);
case MockRepo.SCHEME:
return new MockRepo(context, uriString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
示例11: stripScheme
import android.net.Uri; //導入方法依賴的package包/類
public static String stripScheme(@NonNull String url) {
try {
Uri uri = Uri.parse(url);
return !InputHelper.isEmpty(uri.getAuthority()) ? uri.getAuthority() : url;
} catch (Exception ignored) {}
return url;
}
示例12: beforeInvoke
import android.net.Uri; //導入方法依賴的package包/類
@Override
protected boolean beforeInvoke(Object receiver, Method method, Object[] args) throws Throwable {
// if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2) {
// final int index = 0;
// if (args != null && args.length > index && args[index] instanceof String) {
// String pkg = (String) args[index];
// if (!TextUtils.equals(pkg, mHostContext.getPackageName())) {
// args[index] = mHostContext.getPackageName();
// }
// }
// }
if (!mLocalProvider && mStubProvider != null) {
final int index = indexFirstUri(args);
if (index >= 0) {
Uri uri = (Uri) args[index];
String authority = uri.getAuthority();
if (!TextUtils.equals(authority, mStubProvider.authority)) {
Uri.Builder b = new Builder();
b.scheme(uri.getScheme());
b.authority(mStubProvider.authority);
b.path(uri.getPath());
b.query(uri.getQuery());
b.appendQueryParameter(Env.EXTRA_TARGET_AUTHORITY, authority);
b.fragment(uri.getFragment());
args[index] = b.build();
}
}
}
return super.beforeInvoke(receiver, method, args);
}
示例13: getDrawableFromResourceUri
import android.net.Uri; //導入方法依賴的package包/類
Drawable getDrawableFromResourceUri(Uri uri) throws FileNotFoundException {
String authority = uri.getAuthority();
if (TextUtils.isEmpty(authority)) {
throw new FileNotFoundException("No authority: " + uri);
}
try {
Resources r = this.mContext.getPackageManager().getResourcesForApplication(authority);
List<String> path = uri.getPathSegments();
if (path == null) {
throw new FileNotFoundException("No path: " + uri);
}
int id;
int len = path.size();
if (len == 1) {
try {
id = Integer.parseInt((String) 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((String) path.get(1), (String) path.get(0), authority);
} else {
throw new FileNotFoundException("More than two path segments: " + uri);
}
if (id != 0) {
return r.getDrawable(id);
}
throw new FileNotFoundException("No resource found for: " + uri);
} catch (NameNotFoundException e2) {
throw new FileNotFoundException("No package found for authority: " + uri);
}
}
示例14: toPath
import android.net.Uri; //導入方法依賴的package包/類
/**
* 從第三方文件選擇器獲取路徑。
* 參見:http://blog.csdn.net/zbjdsbj/article/details/42387551
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String toPath(Context context, Uri uri) {
if (uri == null) {
LogUtils.verbose("uri is null");
return "";
}
LogUtils.verbose("uri: " + uri.toString());
String path = uri.getPath();
String scheme = uri.getScheme();
String authority = uri.getAuthority();
//是否是4.4及以上版本
boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
String docId = DocumentsContract.getDocumentId(uri);
String[] split = docId.split(":");
String type = split[0];
Uri contentUri = null;
switch (authority) {
// ExternalStorageProvider
case "com.android.externalstorage.documents":
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
break;
// DownloadsProvider
case "com.android.providers.downloads.documents":
contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
return _queryPathFromMediaStore(context, contentUri, null, null);
// MediaProvider
case "com.android.providers.media.documents":
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
String selection = "_id=?";
String[] selectionArgs = new String[]{split[1]};
return _queryPathFromMediaStore(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else {
if ("content".equalsIgnoreCase(scheme)) {
// Return the remote address
if (authority.equals("com.google.android.apps.photos.content")) {
return uri.getLastPathSegment();
}
return _queryPathFromMediaStore(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(scheme)) {
return uri.getPath();
}
}
LogUtils.verbose("uri to path: " + path);
return path;
}
示例15: toPath
import android.net.Uri; //導入方法依賴的package包/類
/**
* 從第三方文件選擇器獲取路徑。
* 參見:http://blog.csdn.net/zbjdsbj/article/details/42387551
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String toPath(Context context, Uri uri) {
if (uri == null) {
// LogUtils.verbose("uri is null");
return "";
}
// LogUtils.verbose("uri: " + uri.toString());
String path = uri.getPath();
String scheme = uri.getScheme();
String authority = uri.getAuthority();
//是否是4.4及以上版本
boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
String docId = DocumentsContract.getDocumentId(uri);
String[] split = docId.split(":");
String type = split[0];
Uri contentUri = null;
switch (authority) {
// ExternalStorageProvider
case "com.android.externalstorage.documents":
if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}
break;
// DownloadsProvider
case "com.android.providers.downloads.documents":
contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
return _queryPathFromMediaStore(context, contentUri, null, null);
// MediaProvider
case "com.android.providers.media.documents":
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
String selection = "_id=?";
String[] selectionArgs = new String[]{split[1]};
return _queryPathFromMediaStore(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else {
if ("content".equalsIgnoreCase(scheme)) {
// Return the remote address
if (authority.equals("com.google.android.apps.photos.content")) {
return uri.getLastPathSegment();
}
return _queryPathFromMediaStore(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(scheme)) {
return uri.getPath();
}
}
//LogUtils.verbose("uri to path: " + path);
return path;
}