1

We are making an App that allows the user to attache Audio, Photos or Videos on a form.

On android 5 thing work ok. On Android 6 & 7, you get the system dialog promoting you to allow the app to use the Camera, selecting Allow causes the following Error,

Error Dialog on Device

Here is the code that we are using,

Code to capture

Any advice would be greatly appreciated...

  • From API 21 and above you need to ask for permissions in Runtime when you are going to use it. Instead of just asking them on the manifest – Ivan Sep 19 '17 at 14:15
  • During our debugging I came to the same conclusion. Viewing the Apps Permissions on the Device show that the app does not have permission to the Camera. Manually turning it on, fixes the problem. –  Sep 19 '17 at 14:49
  • Could you give me an example of how to request permissions during run time. –  Sep 19 '17 at 14:49
  • Since the camera API invokes an intent it doesn't need a permission. It's unclear what you have within your application that triggered that – Shai Almog Sep 20 '17 at 04:29
  • The exception happens every time I call Capture.capturePhoto() or Capture.capturePhoto(). –  Sep 20 '17 at 21:43
  • As soon as I manually turn on Camera permission for the App, the exception goes away and app behaves as expected. –  Sep 20 '17 at 21:45
  • I've set the Android Target Version to 23, and the ZBar Barcode Scanning Library injects the XPermissions for the camera. [link](https://imgur.com/a/3if4v) –  Sep 20 '17 at 21:51
  • I have the same issue trying to use the camera on android 7. I don't understand how the accepted answer corrects the issue. Do we have to implement nativ android code to ask the android permission at run time ? Maybe you need more details, perhaps I could ask a new question to show you how do I get to this problem. To give you some details: I have tried with and without camera permission in build hint. I call the camera with a simple Button. In addition to this, the QRscanner lib can't access to the camera and causes the crash of the applicarion @ShaiAlmog – John Sep 23 '17 at 09:54
  • The accepted answer is obviously wrong. See this question which is better but still unresolved: https://stackoverflow.com/questions/45548597/codenameone-capture-capturephoto-requests-wrong-permission/45559472#45559472 – Shai Almog Sep 24 '17 at 04:02

1 Answers1

0

You have to check the permissions in runtime from Android 21 API and above. Here you have some info:

Android Developers

Stack Overflow answer

Ivan
  • 782
  • 11
  • 23