Android的奇巧图像选择从库问题 [英] Android kitkat Image Selection From Gallery Issue

查看:117
本文介绍了Android的奇巧图像选择从库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图从存储框架已奇巧4.4改变它是一个头疼的问题我实现这个functionality..I都提到了这个链接<一台Nexus devices..Since的画廊挑选图片href=\"http://stackoverflow.com/questions/20260416/retrieve-absolute-path-when-select-image-from-gallery-kitkat-android\">retrieve当从图库中选择图片奇巧的android 绝对路径

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

我收到文件的路径在gallery..and也去code中的图像,并立即设置到imageView..but我做this..My应用突然关闭,并再次重新连接到服务器并告诉我登录again..Could人请告诉我这种happenings..is存在添加任何许可或更多件$原因C $ç..

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..

这是code用于获取的ImagePath ..

this is the code for getting the 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();

感谢和问候。

推荐答案

最有可能你正在因为该行的java.lang.SecurityException异常

Most probably you are getting java.lang.SecurityException because of this line

getContentResolver().takePersistableUriPermission(originalUri, takeFlags);

试图捕获异常,并应工作。

try to catch exception and should work.

这篇关于Android的奇巧图像选择从库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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