在android 6.0.1中,检索相机照片不工作

1-
一些同事(谁是Android开发人员使用android studio)
当他在我的手机上测试他的应用程序(这是一个与Android 6.0.1的nexus 5)时面临的一个问题,他面临的问题是,当他从画廊拍摄图像时,他可以与他一起工作,但是当采取相机中的照片显示为无,他怀疑他在电话上储存的图像不会得到保存,他怀疑这是一个许可问题,因为它在星系上工作,但不在线上.

2-
同样的事情发生在我身上
我买了一个以前在手机上工作的插件(当我拍摄相机照片时),现在我更新之后不再使用图像,我的意思是我去相机,回到应用程序,没有任何加载像以前一样进入视野.

这是logcat显示的

--------- beginning of main 
02-07 16:36:10.272      203-813/? D/audio_hw_primary﹕ out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2 
02-07 16:36:10.282      203-813/? D/audio_hw_primary﹕ select_devices: out_snd_device(2: speaker) in_snd_device(0: none) 
02-07 16:36:10.282      203-813/? D/msm8974_platform﹕ platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15) 
02-07 16:36:10.282      203-813/? D/audio_hw_primary﹕ enable_snd_device: snd_device(2: speaker) 
02-07 16:36:10.284      203-813/? D/audio_hw_primary﹕ enable_audio_route: apply and update mixer path: low-latency-playback 
02-07 16:36:10.289  24484-24484/? W/CAM_ActivityCloser﹕ WARNING: Activity was artificially finished: CameraActivityController was closed. 
02-07 16:36:10.302  24484-24484/? I/CAM_2RsmeActvtyFltr﹕ START onPause: Activity = com.android.camera.util.activity.DoubleOnResumeActivityFilter@d1e256d 
02-07 16:36:10.303  24484-27584/? W/CAM2PORT_AndCamAgntImp﹕ Releasing camera without any camera opened. 
02-07 16:36:10.305  24484-24484/? I/CAM_2RsmeActvtyFltr﹕ END onPause: Activity = com.android.camera.util.activity.DoubleOnResumeActivityFilter@d1e256d 
02-07 16:36:10.316  25275-25275/? D/CameraController﹕ onActivityResult 
02-07 16:36:10.316  25275-25275/? D/CameraController﹕ RESULT_OK 
02-07 16:36:10.329  25275-25275/? I/Unity﹕ **[CameraDemo] onCaptureImageFail**

为什么会发生这种情况?又如何解决呢?

您必须在活动中要求许可

在你的功能:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (!Settings.System.canWrite(this)) {
            requestPermissions(new String[]{Manifest.permission.CAMERA,
                    Manifest.permission.CAMERA}, REQUEST_CAMERA);
        } else {
            takeFromCamera();
        }
    } else {
        takeFromCamera();
    }

并将其添加到您的活动中

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CAMERA) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                takeFromCamera();
            } else {
                Log.e("Permission", "Denied");
            }
    }
}

在清单中:

<uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
翻译自:https://stackoverflow.com/questions/35254808/in-android-6-0-1-retrieving-the-camera-photo-is-not-working

转载注明原文:在android 6.0.1中,检索相机照片不工作