开发者

Wrong Image Link from the Picture Picker

Hy!

I have a Image Picker and the the problem is that i always get wrong path to the selected picture.

Code:

startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1);
    ....
    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == 1) {
                if (resultCode == RESULT_OK) {
                    Uri uri = 开发者_如何学Pythondata.getData();
                    Log.e("XXX",uri.getPath());
        }

Log:

05-26 18:42:24.766: ERROR/XXX(3290): /external/images/media/2

The right link should be /scdard/test.jpg

Please help


Please see the link below:

Image path

Hope it Helps!


Don't use getPath(). Instead, use a Cursor to get the path, something like this:

String[] proj = { MediaColumns.DATA };
Cursor cursor = managedQuery(uri, proj, null, null, null);
int col_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
cursor.moveToFirst();
String path = cursor.getString(col_index); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜