Android Question [SOLVED] ACTIVITY_RECOGNITION permission Android 11

roncoa

Member
Licensed User
Longtime User
After updating my phone to Android 11, my app using the permissions of ACTIVITY_RECOGNITION, no longer works.

Now the app crashes on startup.
I get this error in debug mode: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference


Immagine 2021-05-19 1959333.jpg



Thank you to those who will help me.
 

roncoa

Member
Licensed User
Longtime User
This is the Log in Debug mode:
Log debug:
Logger connesso a:  Xiaomi M2101K9AG
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
Starting Auto Car Bluetooth
Error occurred on line: 23 (Starter)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
    at anywheresoftware.b4a.objects.RuntimePermissions.CheckAndRequest(RuntimePermissions.java:94)
    at roncoa.AutoCarBluetooth.starter$ResumableSub_Service_Create.resume(starter.java:264)
    at roncoa.AutoCarBluetooth.starter._service_create(starter.java:184)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at roncoa.AutoCarBluetooth.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4290)
    at android.app.ActivityThread.access$1700(ActivityThread.java:257)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2001)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8060)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
** Service (starter) Start **

Crashes in this sub:
The line 23 where crashes is:
rp.CheckAndRequest("android.permission.ACTIVITY_RECOGNITION")
You can see it below.
Service_Create:
Sub Service_Create
    client.Initialize
    Blutooth.Initialize("Bluetooth")
    If LOG_List.IsInitialized=False Then LOG_List.Initialize
    LOG_List.Add(DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now))
    LOG_List.Add("Starting " & Application.LabelName)
    Log("Starting " & Application.LabelName)
    Dim p As Phone
    If p.SdkVersion >= 29 Then
        rp.CheckAndRequest("android.permission.ACTIVITY_RECOGNITION")
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        LOG_List.Add(DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now))
        LOG_List.Add("android.permission.ACTIVITY_RECOGNITION: " & Result)
        If Result = False Then
            ToastMessageShow("No permission", True)
            Return
        End If
    End If
    ' Dim activities As List = Array("IN_VEHICLE", "ON_BICYCLE", "ON_FOOT", "STILL", "UNKNOWN", "TILTING", "", "WALKING", "RUNNING")
    Dim activities As List = Array("IN_VEHICLE", "ON_BICYCLE", "ON_FOOT", "STILL", "WALKING", "RUNNING")
    Wait For (client.RequestTransitionUpdates(activities)) Complete (Success As Boolean)
    Log("RequestTransitionUpdates(activities): " & Success)
    Crea_notifica("ActivityType:UNKNOWN", " TransitionType:UNKNOWN")
    If Main.App_aperta Then
        CallSub(Main,"Refresh_LOG")
    End If
End Sub

Manifest:
Manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
AddPermission(com.google.android.gms.permission.ACTIVITY_RECOGNITION)
AddPermission(android.permission.ACTIVITY_RECOGNITION)

Need more information?

Thanks again.
 
Upvote 0
Top