android根据图片资源的drawable id转化为Uri,java

android根据图片资源的drawable id转化为Uri的工具方法,java

    public Uri getUriFromResId(@NonNull Context context, @AnyRes int drawableId) {
        return Uri.parse(
                ContentResolver.SCHEME_ANDROID_RESOURCE
                        + "://" + context.getResources().getResourcePackageName(drawableId)
                        + '/' + context.getResources().getResourceTypeName(drawableId)
                        + '/' + context.getResources().getResourceEntryName(drawableId)
        );
    }

你可能感兴趣的:(Android,android,java)