我在onActivityResult方法中获得的Uri,我试图使全局Uri变量使该Uri使用Intent putExtra方法将其发送到另一个活动..但它显示无法解析符号。
onActivityResult 方法中的选定图像变量,我希望该 Uri 变量的值在方法之外,以便我可以使用该 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;
}
}
只需在上面声明以下代码 Oncreate
private Uri fileUri;