Android Question API 24+ Permissions request Problem, SOLUTION provided.

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi All

Has anyone experienced issues with the RuntimePermissions lib on API 24+

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
   Dim p As Phone
   Dim rp As RuntimePermissions
   
   ' // instance common data/objects   
   If FirstTime Then
     init_timers
     If Not(APPSET.IsInitialized) Then
       mod_functions.intialise_app_data
     End If
     ac1.Initialize("AC1", ac1.VERTICAL)
     make_menus_ac1
   End If
   
   ' // 6.0+   
   If p.SdkVersion >= 23 Then    
     ' // device   
     rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
     rp.CheckAndRequest(rp.PERMISSION_BODY_SENSORS)
     rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
     rp.CheckAndRequest(rp.PERMISSION_CAMERA)   
     rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
     rp.CheckAndRequest(rp.PERMISSION_PROCESS_OUTGOING_CALLS)
     ' // storage
     rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
     rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE   )   
     ' // sms
     rp.CheckAndRequest(rp.PERMISSION_RECEIVE_SMS)
     rp.CheckAndRequest(rp.PERMISSION_READ_SMS)
     rp.CheckAndRequest(rp.PERMISSION_SEND_SMS)
     ' // gps
     rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
     rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
   Else
     If FirstTime Then
       create_startup
     End If
   End If
   
     
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
   
   mod_functions.writelog("main(), Activity_PermissionResult, " & Permission & ", " & Result)
   APPSET.RP = APPSET.RP + 1

   If APPSET.RP >= 10 Then
     create_startup
   End If

End Sub

In the Activity_PermissionResult sub the Permission string is blank. The only Permission popup is the Phone.

The above code works on api 23 and below. The Test we did was on a real device with 24, I am running test also on 24 emulator using GeneMotion.

When you go to the app permissions the this is what you see.



You need to set them manually.

Regards

John.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that this is not the recommended usage for runtime permissions.
1. You should only request permissions when you need to.
2. You don't need to treat devices differently based on the version. You can always call CheckAndRequest. The PermissionResult will fire immediately on Android 22-.

Are the permissions listed in the manifest editor?

Can you upload your project?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User


Hi Erel

Thanks for the quick reply.

I cannot upload the project.

1. The permissions are listed in the manifest file.
2. In relation to the usage of permissions being requested, they must be set before the user can use the app. The reason being this is personal safety app and if the user activates the app in an situation where they cannot set the permissions to use the locations services to get their GPS position, the app is no good.
3. In relation to point 2 you make, requesting permissions does behave differently on 23 and 24. On 23 all the requests are presented. On 24 the first on is requested, and the other are 'ignored', the result event occurs be with no request permission string.


I have come up with a method that now works on 24, works on the emulator, will test on real device later.

Regards

John.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The reason being this is personal safety app and if the user activates the app in an situation where they cannot set the permissions to use the locations services to get their GPS position, the app is no good.
In that case I would have recommended you to set the targetSdkVersion to 22 or below.

I'm using an Android 7 and didn't encounter any special permissions issue. If you can reproduce it in a small project then I can further check it.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
In that case I would have recommended you to set the targetSdkVersion to 22 or below.

I'm using an Android 7 and didn't encounter any special permissions issue. If you can reproduce it in a small project then I can further check it.

I'll Knock together a sample and post it here for you.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
@Erel sample project , btw I tried to upload the project using the upload a file button but got a permissions error, had to drag and drop.

Talk to you later

J.
 

Attachments

  • api24_permissions.zip
    5.1 KB · Views: 347
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Attached is a solution method that I have used because of the nature of my app.
This method may not be relevant to other developers but it does show how to over come the problem I had with the original method I was using, which did work on api 23, but not api 24+.

@Erel
@DonManfred
@corwin42

Regards

John
 

Attachments

  • api24_permissionssolution.zip
    5.8 KB · Views: 392
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…