Android Question First time working with a Service - get java error using RuntimePermissions

tseyfarth

Member
Licensed User
Longtime User
Hello all,

Moving forward on my project I started a Service to handle in the background BLE.

It appears to start up OK, but when I go to check and request a permission (code below), the app crashes. I've tried having the rp variable in either the BLE Service or in the Starter (as a Public Var). Neither location makes a difference, it always crashes at the point shown below.

B4X:
    For Each Permission As String In Array("android.permission.ACCESS_FINE_LOCATION", "android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_CONNECT")
        Log("Permission = " & Permission )

        
        #If B4A or B4i
            rp.CheckAndRequest(Permission)            <<==========  Error
    '        Starter.rp.CheckAndRequest(Permission)  <<====  Error (when not remarked)
        #End If
        
        
        Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)

This is the error message provided - there are several other lines, but not really sure how much anybody might need to provide some help...
Error Log:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference

Any ideas, direction or help would be greatly appreciated!
Thank you,
Tim
 

MarcoRome

Expert
Licensed User
Longtime User
rp.CheckAndRequest can only be called from an Activity. (also if rp.Check can be called from a service)

Read this
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…