Android Question BroadCastReceiver - PROVIDERS_CHANGED

Discussion in 'Android Questions' started by sangee, Mar 1, 2018.

  1. sangee

    sangee Member Licensed 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)

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

     
  2. DonManfred

    DonManfred Expert Licensed User

    you did not Initialize the BCR! Put a
    Code:
    Brostcast.initilize("BroadcastReceiver")
    as 1st line...

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

    sangee Member Licensed User

    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

    Code:
    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..
     
  4. Erel

    Erel Administrator Staff Member Licensed User

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