0
我尝试从相机发送图像到我的活动。我叫startActivityForResult从适配器这样的:startActivityForResult返回数据null
photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
mActivity.dispatchTakePictureIntent(part.getId());
}
});
这里有一个活动是方法:
public void dispatchTakePictureIntent(String id) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.eltegps011.eltegps.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
takePictureIntent.putExtra("Id",id);
startActivityForResult(takePictureIntent, CAM_REQUEST);
}
}
}
,这是我的onActivityResult();
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 2) {
part = (Part) data.getSerializableExtra("Part");
Log.e(TAG, "onActivityResult: ");
}if(requestCode == 1313) {
Bitmap thumbnail = (Bitmap)data.getExtras().get("data");
String id = data.getStringExtra("Id");
Log.e(TAG, "onActivityResult: " + id);
}
然而,位图的缩略图=(位图)data.getExtras()。获得( “数据”)为空并且resultCode为始终是-1。它看起来像意图不去活动。任何想法为什么?
后续[此](http://stackoverflow.com/a/13977619/5296734)它可帮助您找到解决方案。 –
'//创建文件时发生错误,并且您仍然继续,就好像什么都没有发生。你应该显示吐司这样说,然后返回。 – greenapps
'photoFile = createImageFile()'。除了检查目录是否可写以外,不需要创建该文件。你可以直接删除它。将创建留给相机应用程序。 – greenapps