发送摄像机意图后立即调用onActivityResult [英] onActivityResult getting called as soon as camera intent is sent

查看:86
本文介绍了发送摄像机意图后立即调用onActivityResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用相机意图在我的应用中启动相机,但是一旦激发了意图onActivityResult就被激发了,我什至还没有拍照.

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.

当我拍照时,选择它并返回我的活动,onActivityResult根本不会被调用

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

这是我启动相机的方式

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();
    }

为什么onActivityResult仅在摄像机意图启动后才被调用?

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

推荐答案

问题是我的清单中的活动设置为singleInstance,显然startActivityForResult不喜欢

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

这篇关于发送摄像机意图后立即调用onActivityResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆