Android Question Android 6 CheckAndRequest always return True


Well-Known Member
Licensed User
Hi guys,
I'm facing a weird problem while trying to understand Android's Runtimepermission.
I've followed the Erel's tutorial here:

It seems that does not matter what is the setting give to a resource (the Camera in this case), the CheckAndRequest methods always return TRUE!
I've done this snippet of code:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private rp As RuntimePermissions
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    wait for Activity_PermissionResult (permission As String, Result As Boolean)
    If Result = True Then
        Log("Camera is permitted")     
        Log("No Camera Permission")
    End If 

End Sub

I'm testing it on a real device with Android 6.
In the APP security menu, if I set ASK FOR ACCESS to the Camera, then as soon I get to the CheckAndRequest I see a popup dialog from the OS, asking me what to do.
Then, any button I press (DISALLOW or GRANT) the return from CheckAndRequest is always true.
If I choose, from the above dialog the option DISALLOW, then the next time I try to run it, the dialog for the choice is not even shown, and the application hangs/close.

This is my manifest file:

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="" android:required="true" />)
AddManifestText(<uses-feature android:name="" android:required="false" />)
AddManifestText(<uses-feature android:name="" android:required="false" />)
AddManifestText(<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(client_activity, android:windowSoftInputMode, adjustResize|stateHidden)
'End of default text.

'********* TabStrip ***********************
CreateResource(drawable, background_tab.xml,
<selector xmlns:android=""
  <item android:state_pressed="true" android:drawable="@color/background_tab_pressed" />
  <item android:state_focused="true" android:drawable="@color/background_tab_pressed"/>
  <item android:drawable="@android:color/transparent"/>
CreateResource(values, colors.xml,
  <color name="background_tab_pressed">#6633B5E5</color>

SetActivityAttribute(dati_activity, android:windowSoftInputMode, adjustResize|stateHidden)

Anybody knows why this happen?
I'm using B4A 8.0, Real Device Android 6. Attached is also a screenshot from the SDK manager, if this make a difference.

Thank you.


  • B4A SDK Manager.PNG
    B4A SDK Manager.PNG
    77.1 KB · Views: 148
Last edited:


Well-Known Member
Licensed User
You need to check the logs. If the process crashes then there should be an error message there.
Yes, there is a Crash report Log, but that log, actually make sense, since actually there was NO PERMISSION granted to the camera.

java.lang.RuntimeException: Camera is being used after Camera.release() was called
    at android.hardware.Camera.setPreviewSurface(Native Method)
    at android.hardware.Camera.setPreviewDisplay(
    at com.dlazaro66.qrcodereaderview.QRCodeReaderView.surfaceCreated(
    at android.view.SurfaceView.updateWindow(
    at android.view.SurfaceView$3.onPreDraw(
    at android.view.ViewTreeObserver.dispatchOnPreDraw(
    at android.view.ViewRootImpl.performTraversals(
    at android.view.ViewRootImpl.doTraversal(
    at android.view.ViewRootImpl$
    at android.view.Choreographer$
    at android.view.Choreographer.doCallbacks(
    at android.view.Choreographer.doFrame(
    at android.view.Choreographer$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)

The problem is exactly that: calling rp.CheckAndRequest(rp.PERMISSION_CAMERA)
produce ALWAYS the same result: TRUE, even if a prompt from the OS is displayed and the user choose not to give the permission.
Since rp.CheckAndRequest give always true as result, how can be possible from the app code to avoid the use of the camera?
Please note that the above is the camera case, but any permission requestes give the same identical result: true everytime for any permission.
Probably is some error in the manifest, but I really do not see where it can be.
I'm using B4A 8.00. There are news about permissions in B4A 8.30? If so, I'll switch to 8.30 then.

Thank you all.
Upvote 0


Well-Known Member
Licensed User
It should work properly with v8.00.

I've just updated Camera 1 example to work with targetSdkVersion 26:

Please try it.
Thank you Erel for your time. I've downloaded the new example.
I've fixed the line 68 of the Main (just using File.DirRootExternal).
I've set the real device to ASK for permission. (The options in the setting panel of the phone was: "Grant", "Deny", "Ask".)
I've then launched your sample and a popup window came from the OS asking what to do: grant access to the camera or deny it.
I've denied it, and application crashed immediately (please see the attached screenshot).
Now, if I try to run the application, no popup from OS and the application crash directly with the same error log.
So, the line ToastMessageShow("No permission!!!", True) is never reached in no cases.


  • Permission Error.PNG
    Permission Error.PNG
    30.5 KB · Views: 121
Upvote 0


Well-Known Member
Licensed User
You should run the example without any changes. Don't modify anything in the settings.
I recommend you to download again, change the package name and run it.

Which device are you using?
Ok, I've done what you said.
The changes in the Main line 68 was mandatory otherwise the compiler do not even compile due an error in the code. At line 68 was:
Dim dir As String = Starter.SharedFolder
But there was was no SharedFolder defined in Starter. That's why I've changed it in File.DirRooExternal.
I've changed the package name in "anywheresoftware.b4a.samples.camera2"
Run the example and it works correctly since at the installation phase, the permission to the camera was granted by default.
BUT as soon I DENY or set to ASK for the permission (and then DENY it), the application crash with the same error log posted before.

The application behave correctly only if the permission is granted. If it is denied it crash and no toastmessage displayed.
I'm using a Meizu M5C (Android 6.0)
Upvote 0


Well-Known Member
Licensed User
and for this you need to use runtimepermissions if you set targetsdk to 26 or higher.
I know, but as you can see, I do not even reach that point, since the program crash at the camera initialization (line 33 in the Main of the Erel's example).
I could even comment out all the Camera1_PictureTaken event.
The problem remain the same...
Upvote 0


Well-Known Member
Licensed User
Nothing.... I've upgraded my B4A to 8.30 but still the same problem.
I've found, by the way, that the call to CheckAndRequest return True even before the OS show the dialog asking for the user action about the permission.
Is this a valid hint for somebody?

Upvote 0


Well-Known Member
Licensed User
was the app installed already in tghee past (using an lower targetsdk?
The apps permissions are remembered in android.

Try to deinstall the app.
Install it again using runtimepermissions.
Just did it.
Disinstalled. Reinstalled. Same problem.
I've discovered another strange behaviour while asking for permissions (Activity.AddMenuItem does not add any item if you ask for some permission), but this is something for another thread.

At moment, CheckAndRequest persist with the behaviour I've described.
Upvote 0


Staff member
Licensed User
The changes in the Main line 68 was mandatory otherwise the compiler do not even compile due an error in the code. At line 68 was:
I've fixed the example.

What you describe sounds like a problem in the device implementation.

Activity.AddMenuItem does not add any item if you ask for some permission
This is expected as you must add menu items before the program returns from Activity_Create. Start a new thread if it is not clear.
Upvote 0