我得到Intent data = null
,我不明白为什么?我正在使用
来自Activity B
(A to B: using an intent too (startActivity())
)的意图如下:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null) {
File image = null;
try {
image = saveImageFile();
} catch (IOException ex) {
Toast.makeText(this, ex.getMessage(),Toast.LENGTH_LONG).show();
}
if (image != null) {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image ));
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
}
} else {
Toast.makeText(this, "Cannot take a picture!", Toast.LENGTH_LONG).show();
}
从我的onActivityResult
我试过这个:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
Bitmap myImageBitmap = (Bitmap) extras.get("data");
scaleMyImage(myImageBitmap);
} else if(resultCode == RESULT_CANCELED) {
finish();
}
}
我在这里保存图片:File storageDirec = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
。从调试我得到正确的参数(requestCode = 1 & resultCode = -1
),但data = null
? - 有人可以告诉/帮助我为什么Intent数据为空? - 谢谢,卡尔