问题:我在三星S3上使用相机意图时,在
onActivityResult(int requestCode, int resultCode, Intent data)
函数中获取到的数据为null,但在其他设备上运行良好。我已经按照自己的需求编写了代码并在网上搜索过此问题,但没有发现有用的信息。
代码:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKE_CAMERA && data != null && data.getData() != null)
else if (requestCode == TAKE_CAMERA) {
if (resultCode != RESULT_OK) return;
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(tempFileUri, "image/*");
intent.putExtra("outputX", 90);
intent.putExtra("outputY", 90);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP_CAMERA);
} else if (requestCode == CROP_CAMERA && data != null) {
Bitmap photo = data.getExtras().getParcelable("data");
try {
FileOutputStream out = new FileOutputStream(tempFileUri.getPath());
photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (photo != null) {
imagePhoto.setImageBitmap(photo);
<my code>
}
}
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
。 - user1621629