B4A Class Marshmallow Permissions

Penguin

Member
Licensed User
Since there is currently no native support for the new permission system in Android 6.0 Marshmallow I wrote a little class for it.

How to use this:

- This Class needs the Phone and the JavaObject Library
- Set the targetSdkVersion in your manifest to at least 23
-
Add the permission you want to request to your Manifest

- Put the following code in your project:
B4X:
Sub Globals

    Private Permission As Mpermission

End Sub

Sub Activity_Create(FirstTime As Boolean)

    Permission.Initialize

    If Permission.CheckPermission ("android.permission.CAMERA") = False Then
        Permission.RequestPermission ("android.permission.CAMERA")
    End If

End Sub
Update Nov 10 2015:
- Added option to show rationale
- Added a simple sample project


Update Mar 14 2016:
- CheckPermission returns alsways "True" when SDK Version < 23

Image.png
 

Attachments

Last edited:

joneden

Active Member
Licensed User
Hi Penguin,

This doesn't seem to work for me. Is it meant to trigger the display of the user prompt or just acquire permissions from the set that are auto allocated (Normal Permission)? I managed to get it working with the Bluetooth permission but that is one of the normal permissions.

The article I have been reading in the hope of resolving this issue is this one: http://inthecheesefactory.com/blog/...out-android-m-permission-developer-edition/en

Regards

Jon
 

joneden

Active Member
Licensed User
Yeah its all properly set to 23 and everything else that depends on it being sdk 23 works.

Just to be clear should the class cause the message (authorisation message that is) to popup on screen? Obviously not seeing a message leaves me unsure if anything is happening or not.

Cheers

Jon
 

Penguin

Member
Licensed User
Yes. It should appear the standard permission dialog of Android Marshmallow (as you can see in the picture I attatched to the first post)
 

joneden

Active Member
Licensed User
Ah that sounds great - good to know that it should be working like that :) thanks for letting me know. Was that picture there all along or did you just add it?
 

joneden

Active Member
Licensed User
Ha ha I thought I must have been losing it last night. Good to know that I didn't miss that initially.

Unfortunately my app even as a new basic example project doesn't work. Any chance you could post your full working project? I can then hopefully work out if there is some device issue or if I missed something, sdk is 23 and everything else is setup right.. :(
 

joneden

Active Member
Licensed User
Great thanks for that. Yes that works. Interestingly I have tried with the permissions that I needed and some of them didn't show the prompt even though the permission is not held eg, android.permission.DUMP

One did work (android.permission.READ_PHONE_STATE) with your code but then in my app if doesn't show the popup.

I think that maybe I have two issues, first issue seems that some of the permssions are ones that can't be obtained or are old or something and then second issue is that where it would display the popup message something in my code is preventing it.

I'll look into more next week and will post the solution once I find out what's happening.

Have a great weekend!
 

joneden

Active Member
Licensed User
Finally got back to this and solved it. I was doing the manifest wrong, I must have had some old permission mechanism present as I was doing it like below:
AddReplacement(<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
instead of
AddPermission ("android.permission.WRITE_SECURE_SETTINGS")

Changed over and it works. Just need to suss out why only one question came up rather than the 3 that needed the prompt but it's a start :)
 

joneden

Active Member
Licensed User
OK so if anyone else runs into problems like I did here is a list of the things I did wrong:
1) Used the AddReplacement code in the Manifest. Not sure where this came from but now use AddPermission (as in previous post)
2) I found just now that I gave myself problems by using the wrong permission - while they made things work previously they didn't seem to be correct eg for some reason I'd used the RECORD_VIDEO rather than CAMERA permission.
3) I was trying to do the permissions singly rather than using RequestMultiplePermissions.

The only comments that I'd have beyond this is that I know there is a callback mechanism that would be good to have access to and also that it would be nice to have the ability to add a rationale to the permission request. If I solve either I'll post here...
 

Penguin

Member
Licensed User
The only comments that I'd have beyond this is that I know there is a callback mechanism that would be good to have access to and also that it would be nice to have the ability to add a rationale to the permission request. If I solve either I'll post here...
As soon as I find the time to do it, i'll try to add this features
 

Walter Adriano da Silva

Member
Licensed User
When I try request the permission I got this:

Caused by: java.lang.RuntimeException: Method: requestPermissions not found in: com.softvale.app.starter
What could be causing this?
Is it possible permission request through a Service?
 

Walter Adriano da Silva

Member
Licensed User
Looking to CheckPermission method

'Returns True when the permission is granted.
'Returns False when the permission is not granted or the SDK Version is smaller than 23
Couldn't be better also return True when the SDK Version is smaller than 23?
Because if the sdk is < 23 then automatically the permission has is granted.
 

Penguin

Member
Licensed User
Looking to CheckPermission method



Couldn't be better also return True when the SDK Version is smaller than 23?
Because if the sdk is < 23 then automatically the permission has is granted.
Updated the Class to return true when SDK < 23


How can we catch user's choice?
Thank you for your time.
For now the only thing you can do for now (with this class) is to run "CheckPermission" after showing the Permission Dialog. As soon as I find the time I will try to add this feature
 
Top