简体   繁体   English

从画廊发行的Android kitkat图像选择

[英]Android kitkat Image Selection From Gallery Issue

I have been trying to pick image from the gallery of Nexus devices..Since the Storage framework has been changed in kitkat 4.4 its been a headache for me to implement this functionality..I have referred to this link retrieve absolute path when select image from gallery kitkat android 我一直在尝试从Nexus设备库中选择图像。.由于在kitkat 4.4中更改了存储框架,因此实现此功能对我来说很头疼。. 当从以下位置选择图像时 ,我已引用此链接获取绝对路径画廊kitkat android

I am getting the path of the file in the gallery..and also decode the image and set it into the imageView..but as soon I do this..My app closes suddenly and again reconnects to the server and tells me to log in again..Could anyone please tell me the reasons for such happenings..is there any permission to be added or some more piece of code.. 我正在库中获取文件的路径,并解码图像并将其设置到imageView中。但是,一旦我这样做,我的应用程序突然关闭并再次重新连接到服务器,并告诉我登录再次..任何人都可以告诉我发生这种情况的原因..是否允许添加任何许可或更多代码段。

this is the code for getting the Imagepath.. 这是获取Imagepath的代码。

    Uri originalUri = data.getData();

            final int takeFlags = data.getFlags()
                                & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Check for the freshest data.
            getContentResolver().takePersistableUriPermission(originalUri, takeFlags);

            String id = originalUri.getLastPathSegment().split(":")[1]; 
            final String[] imageColumns = {MediaStore.Images.Media.DATA };
            final String imageOrderBy = null;

            Uri uri = getUri();

            @SuppressWarnings("deprecation")
            Cursor imageCursor = managedQuery(uri, imageColumns,
                  MediaStore.Images.Media._ID + "="+id, null, imageOrderBy);

            if (imageCursor.moveToFirst())
            {
                picturepath = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
            }
            Bitmap b=decodeSampledBitmapFromFile(picturepath, 175, 175);
            imgToBeUploaded.setImageBitmap(b);
            Toast.makeText(StartingActivity.this, picturepath, Toast.LENGTH_SHORT).show();

Thanks and Regards. 谢谢并恭祝安康。

Most probably you are getting java.lang.SecurityException because of this line 由于此行,很可能您正在获取java.lang.SecurityException

getContentResolver().takePersistableUriPermission(originalUri, takeFlags);

try to catch exception and should work. 尝试捕获异常,应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM