/**
* get uri to any resource type
*
* @param resId - resource id
* @return - Uri to resource by given id
*/
public static Uri getUriToResource(@NonNull Activity activity, @AnyRes int resId) {
Uri resUri = null;
try {
/** Return a Resources instance for your application's package. */
Resources res = activity.getResources();
/**
* Creates a Uri which parses the given encoded URI string.
* @param uriString an RFC 2396-compliant, encoded URI
* @throws NullPointerException if uriString is null
* @return Uri for this given uri string
*/
resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + res.getResourcePackageName(resId) + '/' + res
.getResourceTypeName(resId) + '/' + res.getResourceEntryName(resId));
/** return uri */
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
return resUri;
}
ResourcesHelper.java 文件源码
java
阅读 38
收藏 0
点赞 0
评论 0
项目:AndroidBlueprints
作者:
评论列表
文章目录