Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in android 6.0.1, retrieving the camera photo is not working

1- Some colleague (who is an android developer using android studio) is facing a problem when he tests his application on my phone (which is a nexus 5 with android 6.0.1), the problem he is facing is that when he takes an image from a gallery it works with him ok, but when taking a photo from the camera it displays none, he suspects that the image he is saving on the phone don't get saved, he suspects it's a permission problem, for him it works on galaxy but not on nexus.

2- the very same thing happens with me in unity I bought a plugin that used to work OK in the past on my phone (when I take a camera photo) and now after I updated It's no longer taking the image, I mean I go to camera and go back to application without having anything loaded into the view like before.

this is what logcat shows

--------- 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**

Why this happens? And how to solve it?

like image 597
DeyaEldeen Avatar asked Feb 07 '16 14:02

DeyaEldeen


3 Answers

You have to ask for permission in activity

in your function :

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

and add this in your activity

@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");
            }
    }
}

in manifest :

<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" />
like image 80
MrZ Avatar answered Nov 18 '22 01:11

MrZ


I don't know much about unity and pardon me if this doesn't help. In general, in order for everything to work properly regarding using the camera hardware and storing the image in native android, the androidmanifest.xml file should include the following inside the application tag:

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

To tweak the manifest file from unity, here's a guide I found: https://matthewongamedesign.wordpress.com/2013/06/08/unity-and-the-android-manifest-file/

like image 32
Ilan Kutsman Avatar answered Nov 18 '22 01:11

Ilan Kutsman


the solution was to ask for permission in an alert, not only grant the permission in manifest.

like image 1
DeyaEldeen Avatar answered Nov 18 '22 01:11

DeyaEldeen