onActivityResult getting called as soon as camera intent is sent

若如初见. 提交于 2020-01-02 04:49:08

问题


I am using the camera intent to launch the camera in my app but as soon as the intent gets fired the onActivityResult gets fired and I have not even taken a picture yet.

When I do take a picture, select it and return back to my activity the onActivityResult does not get called at all

here is how I launch the camera

PackageManager pm = getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        File tempDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"Mobile Map");
        if (!tempDir.exists()) {
            if (!tempDir.mkdir()) {
                Toast.makeText(this,
                        "Please check SD card! Image shot is impossible!",
                        Toast.LENGTH_SHORT).show();
            }
        }

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US).format(new Date());
        File mediaFile = new File(tempDir.getPath() + File.separator+ "IMG_" + timeStamp + ".jpg");

        photoUri = Uri.fromFile(mediaFile);
        camera.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
        startActivityForResult(camera, CAMERA_REQUEST);
    } else {
        Toast.makeText(this,"This device does not have a rear facing camera",Toast.LENGTH_SHORT).show();
    }

Why is the onActivityResult only getting called after the camera intent launches?


回答1:


The problem was that in my manifest I had the activity set to singleInstance and apparently startActivityForResultdoes not like that



来源:https://stackoverflow.com/questions/16592623/onactivityresult-getting-called-as-soon-as-camera-intent-is-sent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!