【问题标题】:Tapping camera save button action opening again camera in android jellybean在android jellybean中点击相机保存按钮动作再次打开相机
【发布时间】:2013-02-22 08:55:46
【问题描述】:

我正在尝试拍照并使用 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..");
    }
}

【问题讨论】:

    标签: android android-camera android-4.2-jelly-bean


    【解决方案1】:

    你的额外参数有问题,使用这个例子here

    【讨论】:

    • 谢谢。你的意思是:intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    猜你喜欢
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多