想要从以下部分设置值 RESULT
并且应该在 onActivityResult
中检索它...
代码如下。
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
System.out.println("Select Display Picture, but");
intent.putExtra("RESULT", "RESULT");
activity.startActivityForResult(
Intent.createChooser(intent, "Select Display Picture"),
Credentials.BROWSE_PIC);
activity.setResult(Credentials.BROWSE_PIC, intent);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Credentials.BROWSE_PIC
&& resultCode == Activity.RESULT_OK && null != data) {
//returning null always here..
System.out.println("OnActivityResult came in::: "
+ data.getStringExtra("RESULT"));
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
}
最佳答案
您正在使用隐式 Intent ,您不能在此 Intent 中放置任何内容,因为每个隐式 Intent 都是由其他人定义的。
如果你想添加一些东西,那么你可以使用你自己的 Global Bundle 对象。
这是给你的重要链接:
您可以查看 Lavekush Agrawer 对使用全局 bundle 对象的回答。这里access the variable in activity in another class
关于java - onActivityResult 使用 putExtra() 选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286131/