Android Question detecting android.net.wifi.WIFI_STATE_CHANGED in background

freedom2000

Well-Known Member
Licensed User
HI,

I would like to detect a change in Wifi conectivity in order to wake up an App

I know that Phone library offers this. But it would need a foreground service with this annoying permament notification.

My question is :
is there a way to intercept android.net.wifi.WIFI_STATE_CHANGED with a static intent ?

Thanks
 

freedom2000

Well-Known Member
Licensed User
Thank you for your answer.

Yes I was asking for the right intent, but also if I could use it with a "static intent" or if I must use a "broadcast receiver".

As far as I have understood, static intents are handled at the system level an can launch the App, and dynamic ones (broadcast receiver) need to be handle inside the App so are only triggered when the App process is launched.

Am I right ?

And of course what I would like is that the system launchs my App when connectivity change (even if it is not yet started).
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Ok it works :)

Add this in your Manifest :
B4X:
'check for any connectivity change
AddReceiverText(CheckWifi,
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>)

Create a service with the Name "CheckWifi" (same name as in your Intent)
B4X:
'Service module
Sub Process_Globals 
End Sub
Sub Service_Create
End Sub

Sub Service_Start(startingIntent As Intent)
   If startingIntent.Action = "android.net.conn.CONNECTIVITY_CHANGE" Then
      ToastMessageShow("wifichanged", True)
   End If
End Sub

And if you switch off or On your Wifi, you get the message :cool:

Even when the App is killed

Everything is soooo easy with @Erel's help !
 
Upvote 0

DonManfred

Expert
Licensed User
Start with creating a new Thread instead of posting to an old Thread.
 
Upvote 0
Top