B4A Class Marshmallow Permissions

Discussion in 'Additional libraries, classes and official updates' started by Penguin, Sep 15, 2015.

  1. Penguin

    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:
    Code:
    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
     

    Attached Files:

    Last edited: Mar 14, 2016
    mendiburen, ilan, Scunkaneli and 9 others like this.
  2. joneden

    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
     
  3. Penguin

    Penguin Member Licensed User

    Have you set the targetSdkVersion in your Manifest to 23?
     
  4. joneden

    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
     
  5. Penguin

    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)
     
    DonManfred likes this.
  6. joneden

    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?
     
  7. Penguin

    Penguin Member Licensed User

    I just added it ;)
     
  8. joneden

    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.. :(
     
  9. Penguin

    Penguin Member Licensed User

    I'll post an example project as soon as I arrive at home today
     
    DonManfred likes this.
  10. joneden

    joneden Active Member Licensed User

    Superb thanks for that. :) Have a good day!
     
  11. Penguin

    Penguin Member Licensed User

    This project works for me. I tested it with a Nexus 6 and with an AVD
     

    Attached Files:

    lazreg and DonManfred like this.
  12. joneden

    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!
     
  13. joneden

    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 :)
     
  14. joneden

    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...
     
  15. Penguin

    Penguin Member Licensed User

    As soon as I find the time to do it, i'll try to add this features
     
  16. Walter Adriano da Silva

    Walter Adriano da Silva Member Licensed User

    When I try request the permission I got this:

    What could be causing this?
    Is it possible permission request through a Service?
     
  17. DonManfred

    DonManfred Expert Licensed User

    I don´t think that this is possible as the Android Permission system expect a Activity which do the permission-requests
     
  18. Walter Adriano da Silva

    Walter Adriano da Silva 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.
     
  19. yiankos1

    yiankos1 Active Member Licensed User

    How can we catch user's choice?
    Thank you for your time.
     
    ilan likes this.
  20. Penguin

    Penguin Member Licensed User

    Updated the Class to return true when SDK < 23


    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
     
    DonManfred and yiankos1 like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice