如果图片是使用android的相机应用程序拍摄的,为什么我不能从图库中上传图片? [英] Why can't I upload a picture from gallery in my android app, if the picture was taken with the camera app from android?

查看:84
本文介绍了如果图片是使用android的相机应用程序拍摄的,为什么我不能从图库中上传图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从图库中上传图片并将其显示在我的Android应用上.例如,如果我从屏幕快照文件夹中选择一个图像,这将很好地工作.但是,当我从存储用手机相机拍摄的照片的文件夹中选择图像时,它不起作用.

I want to upload an image from gallery and show it on my Android app. This works fine if I select an image from the screenshot folder for example. But when I select an image from the folder where the pics, taken with the phone camera, are stored, it does not work.

    public void UploadPicture(View v) {
    Intent pickPhoto = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(pickPhoto , 1);


protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    switch (requestCode) {
        case 1:
            if (resultCode == RESULT_OK) {
                Uri selectedImage = imageReturnedIntent.getData();
                imageView.setImageURI(selectedImage);
            }
            break;
    }
}

推荐答案

在我看来,这些问题可以通过诸如Ucrop之类的ImagePicker库来解决.适用于Android的Ucrop库

In my opinion, these problems can be solved by ImagePicker Libraries such as Ucrop. Ucrop Library For Android

确保已处理运行时"权限.为了更轻松地处理权限,您可以使用Dexter Dexter

Make sure you have Runtime permission Handled. For easier permission handling you can use Dexter Dexter

确保清单文件中具有u外部存储读取权限.如果要从相机拍摄图像,可能还需要同时具有读取/写入"权限.

Make sure u have External Storage Read permission in your manifest file. You may also require both Read/Write permission if you want to take image from camera.

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

注意:对于Pie以上版本的android版本,请将这些属性粘贴到manifest.xml的应用程序标记中:

Note: for android version above Pie paste these attributes in application tag in manifest.xml :

<application
        android:preserveLegacyExternalStorage="true"
        android:requestLegacyExternalStorage="true"
        ... >
...
...
</application>

这篇关于如果图片是使用android的相机应用程序拍摄的,为什么我不能从图库中上传图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆