我在onActivityResult方法中获得的Uri,我尝试使用全局Uri变量来使Uri使用Intent putExtra方法将其发送到另一个活动..但它显示无法解析符号。
onActivityResult方法中的 selectedImage 变量,我希望该方法之外的Uri变量的值,以便我可以使用Intent将该Uri发送到另一个活动。
如何获取它的值作为onActivityResult的返回类型是无效的?
帮助我还是有其他办法吗?
public void onClickPickImage(View view){
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);//zero can be replaced with any action code
Intent pickPhoto = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);//one can be replaced with any action code
}
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
switch(requestCode) {
case 0:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
}
break;
case 1:
if(resultCode == RESULT_OK){
Uri selectedImage = imageReturnedIntent.getData();
}
break;
}
}
答案 0 :(得分:-1)
只需在Oncreate
上面声明以下代码即可private Uri fileUri;