android获取返回图片的绝对路径

来源:互联网 发布:剑灵捏脸动漫人物数据 编辑:程序博客网 时间:2024/09/21 08:55

public final static int CONSULT_PICTURE = 100;



Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);  
startActivityForResult(intent, CONSULT_CAMERA);





if(resultCode==RESULT_OK && requestCode==CONSULT_CAMERA) {        

            Uri uri = data.getData();  
            if (!TextUtils.isEmpty(uri.getAuthority())) {  
                //查询选择图片  
                Cursor cursor = getContentResolver().query(  
                        uri,  
                        new String[] { MediaStore.Images.Media.DATA },  
                        null,   
                        null,   
                        null);  
                //返回 没找到选择图片  
                if (null == cursor) {  
                    return;  
                }  
                //光标移动至开头 获取图片路径  
                cursor.moveToFirst();  
                String path = cursor.getString(cursor  
                        .getColumnIndex(MediaStore.Images.Media.DATA));  
                //向处理活动传递数据
Toast.makeText(this, path, Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(this, ProcessActivity.class); //主活动->处理活动
// intent.putExtra("path", path);
// //startActivity(intent);
// startActivityForResult(intent, GET_DATA);

}
0 0
原创粉丝点击