当前位置: 首页>>代码示例>>Java>>正文


Java Uri.getAuthority方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:ResourceDrawableDecoder.java

示例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);
    }
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:46,代码来源:IconHelper.java

示例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);
        }
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:26,代码来源:IContentServiceHandle.java

示例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 };
  }
}
 
开发者ID:google,项目名称:samba-documents-provider,代码行数:28,代码来源:MountServerActivity.java

示例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));
}
 
开发者ID:Doist,项目名称:JobSchedulerCompat,代码行数:15,代码来源:AlarmSchedulerTest.java

示例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);
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:31,代码来源:NativeAppCallAttachmentStore.java

示例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);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:35,代码来源:SuggestionsAdapter.java

示例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();
    }
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:11,代码来源:DocumentsApplication.java

示例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;
  }
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:28,代码来源:DefaultUriAdapter.java

示例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;
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:35,代码来源:RepoFactory.java

示例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;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:8,代码来源:LinkParserHelper.java

示例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);
        }
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:32,代码来源:IContentProviderInvokeHandle.java

示例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);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:33,代码来源:SuggestionsAdapter.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:66,代码来源:ConvertUtils.java

示例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;
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:66,代码来源:ConvertUtils.java


注:本文中的android.net.Uri.getAuthority方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。