我正在尝试使用 startActivityForResult() 拍照并将其保存到文件中。但是在点击“保存”按钮后它没有保存任何东西并再次打开相机。使用设备三星 Galaxy S3(4.1.1) 和三星 Galaxy Nexus(4.1.1),但它与摩托罗拉 Defy(2.3.4) 一起工作正常。是 Android OS 4.1.1 还是 Device 的问题?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File file = null;
Date date = new Date();
try {
file = new File("photosearch-"+date.getTime()+".jpeg");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
Log.e(TAG, " startActivityForResult");
startActivityForResult(intent, CAMERA_ACTIVITY);
} catch (Exception e) {
Log.d(TAG, ""+e);
//Check if sdcard is accessible
Toast.makeText(getActivity(), "Unable to access SD Card", Toast.LENGTH_LONG).show();
getActivity().finish();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult....");
if(resultCode == Activity.RESULT_CANCELED){
Intent intent = new Intent(getActivity(), AnotherListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
getActivity().finish();
}
if(resultCode == CAMERA_ACTIVITY){
Log.d(TAG, "It should come here..");
}
}