1

CodenameOne's Capture.capturePhoto(1000, -1) seems to work fine with Android targetSDKVersion 21 permissions. But on 23 it wrongly requests a

Allow [...] to access photos media, and files on your device?

permission from the user, but then fails because of the android.permission.CAMERA missing.

(The simulator in lack of a camera requests media files instead - could there be something mixed up?)

UPDATE (DDMS output)

08-09 15:13:47.866: W/ActivityManager(1676): Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x4000003 cmp=com.sec.android.app.camera/.Camera clip={text/uri-list U:file:///storage/emulated/0/Pictures/XXX/IMG_20170809_151347.jpg} (has extras) } from ProcessRecord{f736f3f 20079:com.XXX/u0a338} (pid=20079, uid=10338) with revoked permission android.permission.CAMERA
08-09 15:13:47.876: W/System.err(20079): java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x4000003 cmp=com.sec.android.app.camera/.Camera clip={text/uri-list U:file:///storage/emulated/0/Pictures/XXX/IMG_20170809_151347.jpg} (has extras) } from ProcessRecord{f736f3f 20079:com.XXX/u0a338} (pid=20079, uid=10338) with revoked permission android.permission.CAMERA
08-09 15:13:47.896: E/ConfigFileUtils(3071): Failed to read config file: /data/data/com.google.android.gms/app_chimera/current_modulesets.pb: open failed: ENOENT (No such file or directory)
08-09 15:13:47.906: W/System.err(20079):    at android.os.Parcel.readException(Parcel.java:1620)
08-09 15:13:47.906: W/System.err(20079):    at android.os.Parcel.readException(Parcel.java:1573)
08-09 15:13:47.906: W/System.err(20079):    at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3131)
08-09 15:13:47.906: W/System.err(20079):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1540)
08-09 15:13:47.906: W/System.err(20079):    at android.app.Activity.startActivityForResult(Activity.java:4283)
08-09 15:13:47.906: W/System.err(20079):    at android.app.Activity.startActivityForResult(Activity.java:4230)
08-09 15:13:47.906: W/System.err(20079):    at com.codename1.impl.android.CodenameOneActivity.startActivityForResult(CodenameOneActivity.java:576)
08-09 15:13:47.906: W/System.err(20079):    at com.codename1.impl.android.c.a(AndroidImplementation.java:5869)
08-09 15:13:47.906: W/System.err(20079):    at com.codename1.u.p.b(Display.java:3109)
08-09 15:13:47.906: W/System.err(20079):    at com.codename1.b.a.a(Capture.java:77)
08-09 15:13:47.906: W/System.err(20079):    at com.codename1.b.a.a(Capture.java:125)
08-09 15:13:47.906: W/System.err(20079):    at com.grandgreat.XXX.ai.b(SettingsForm.java:98)

(SettingsForm.java:98 String path = Capture.capturePhoto(1000, -1); )

1 Answers1

0

This should have worked since we use an Intent which does all the work of capturing so we don't even request that permission. See the code here.

However, as explained by this stack overflow question Android M Camera Intent + permission bug?

If the app has a camera permission the intent might fail to prevent what appears to be a misbehavior. Again a horrible edge case of the intent system...

The workaround is indeed to prompt for camera permission which we will add for the update tomorrow (August 11th 2017).

Shai Almog
  • 51,749
  • 5
  • 35
  • 65