Android Question BroadCastReceiver - PROVIDERS_CHANGED

sangee

Member
Licensed User
Longtime User
Hello All,

I am trying an option in my new app to detect when the user disables the GPS. Code is as below (took from the example)

B4X:
Sub Process_Globals
   Dim Broadcast As BroadCastReceiver
End Sub

Sub Service_Start (StartingIntent As Intent)
'Listen for GPS on or off intent
   Broadcast.addAction("android.location.PROVIDERS_CHANGED")
   Broadcast.SetPriority(2147483647)
   Broadcast.registerReceiver("")
End Sub


Sub BroadcastReceiver_OnReceive (Action As String)
     ToastMessageShow(Action,False)
      Log("GPS disabled")
      'can only abort when sendOrderedbroadcast is called.
      'Broadcast.AbortBroadcast
End Sub

This is triggering error when I switch on or off the GPS (location on/off) in the settings.

The error is below.. Can anyone let me know how to detect when a user switches on/off the GPS.

Regards,
Sangee

java.lang.Exception: Sub broadcastreceiver_onreceive signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:171)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at com.rootsoft.broadcastreceiver.BroadCastReceiver$1.onReceive(BroadCastReceiver.java:110)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.location.GPS_ENABLED_CHANGE flg=0x10 (has extras) } in com.rootsoft.broadcastreceiver.BroadCastReceiver$1@a8fd6b3
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:891)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.RuntimeException: java.lang.Exception: Sub broadcastreceiver_onreceive signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at com.rootsoft.broadcastreceiver.BroadCastReceiver$1.onReceive(BroadCastReceiver.java:110)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:881)
... 7 more
Caused by: java.lang.Exception: Sub broadcastreceiver_onreceive signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:171)
... 10 more
 

DonManfred

Expert
Licensed User
Longtime User
Sub Service_Start (StartingIntent As Intent)
'Listen for GPS on or off intent
Broadcast.addAction("android.location.PROVIDERS_CHANGED")
Broadcast.SetPriority(
2147483647)
Broadcast.registerReceiver(
"")
End Sub
you did not Initialize the BCR! Put a
B4X:
Brostcast.initilize("BroadcastReceiver")
as 1st line...

Check the description in the BCR Library thread....
 
Upvote 0

sangee

Member
Licensed User
Longtime User
you did not Initialize the BCR! Put a
B4X:
Brostcast.initilize("BroadcastReceiver")
as 1st line...

Check the description in the BCR Library thread....

Sorry.. I had missed out on pasting that part of the code when posting this thread. I have already set the "initialize" in the Service create Sub like below

B4X:
Sub Service_Create
    
    If Notification.IsInitialized = False Then
        Notification.Initialize
        Notification.Icon = "icon"
        Notification.SetInfo("test", "test", Main)
        Notification.Sound = False
        Notification.Vibrate = True
    End If
    Broadcast.Initialize("BroadcastReceiver")
End Sub

The error is there even with this already. Not able to understand why trapping this intent is throwing error and causing the application to crash..
 
Upvote 0
Top