【问题标题】:Request Google Photos Permission请求 Google 相册权限
【发布时间】:2017-12-19 10:54:37
【问题描述】:

我的应用中有一个图像选择器。

  • 当我从 Google 照片中选择一张图片时,我必须保存它的 URI
  • 然后我需要使用这个 URI 将这个图像显示到一个 ImageView 中。
  • 我尝试请求 Google 照片权限,但没有结果。

public static final String GOOGLE_PHOTOS_PERMISSION="com.google.android.apps.photos.permission.GOOGLE_PHOTOS";

是否可以通过 URI 从 Google 相册获取图片?

【问题讨论】:

标签: android android-permissions google-photos


【解决方案1】:

您可以使用Picasso 库。

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

使用 Gradle 文件

compile 'com.squareup.picasso:picasso:2.5.2'

查看毕加索图书馆文档

【讨论】:

    【解决方案2】:

    使用这个 sn-p 将 Uri 转换为 Bitmap

    private Bitmap getBitmapFromUri(Uri uri) throws IOException {
        ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");
        FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
        Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
        parcelFileDescriptor.close();
        return image;
    }
    

    现在将此Bitmap 设置为ImageView

    【讨论】:

    • 同样的结果。需要导出提供程序,或 grantUriPermission()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多