How to test if user has enabled wifi and/or data connections?

cb56

Member
Licensed User
Longtime User
Please, do you know how to test if user has enabled wifi and/or data connections?

I do not mean if the connections mobile and/or wifi is available, I can do it, but if the two type of connections are enabled.

Possibly there is a broadcast message to intercept?

Thanks

cb56
 
Last edited:

cb56

Member
Licensed User
Longtime User
Than, what do you mean with "enabled"?
In your first post you said, that you are not interested in available-informations.

I mean when a user enable or disable Wifi and/or data connections in device settings.

This can be done also in the notification widget and the button line become green/gray.

cb56
 
Upvote 0

cb56

Member
Licensed User
Longtime User
Exactly therfore exists the ConnectivityChanged-event of the PhoneEvents-object.

It seems to me that this event don't fires if you enable wifi and/or mobile but there is no signal or, for wifi, no known spot....

Also, if you disable wifi and/or mobile when there is non connectivity (Connectivity not Changed) this event don't fires.

cb56
 
Upvote 0

cb56

Member
Licensed User
Longtime User
Please show us some code.

Here it's working well!

If you turn off your router and there are no known wifi spot, if you enable or disable wifi the sub "PE_ConnectivityChanged" don't fires.

cb56

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim PE As PhoneEvents
   Dim PhoneId As PhoneId
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   
   PE.InitializeWithPhoneState("PE", PhoneId)

End Sub

Sub Activity_Resume
   
   Activity.LoadLayout ("Main")
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub PE_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)

   Log("-----------------------------------")
   Log("")
   Log("ConnectivityChanged: " & NetworkType & ", state = " & State)
   Log(Intent.ExtrasToString)
   
End Sub
 
Upvote 0

monki

Active Member
Licensed User
Longtime User
The Dokumentation say

The Android OS sends all kinds of messages to notify applications of changes in the system.The PhoneEvents object allows you to catch such messages and handle those events in your program.Usually you will want to add this object to a Service module instead of an Activity module in order not to miss events that happen whileyour activity is paused.

Monki
 
Upvote 0

cb56

Member
Licensed User
Longtime User
The Dokumentation say

The Android OS sends all kinds of messages to notify applications of changes in the system.The PhoneEvents object allows you to catch such messages and handle those events in your program.Usually you will want to add this object to a Service module instead of an Activity module in order not to miss events that happen whileyour activity is paused.

Monki


Thank you, but even in a service the routine "ConnectivityChanged" is performed only when precisely the connectivity changes (you can try this code), it is not what I'm looking for.

B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

   Dim PE As PhoneEvents
   Dim PhoneId As PhoneId

End Sub
Sub Service_Create

   PE.InitializeWithPhoneState("PE", PhoneId)
   
End Sub

Sub Service_Start (StartingIntent As Intent)
   
   PE.InitializeWithPhoneState("PE", PhoneId)

End Sub

Sub Service_Destroy
   
   PE.StopListening
   
End Sub

Sub PE_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)

   Log("-----------------------------------")
   Log("")
   Log("ConnectivityChanged: " & NetworkType & ", state = " & State)
   Log(Intent.ExtrasToString)
   
End Sub

I'm looking for a way to intercept the event that fires when a user change the settings of connectivity (wifi and or mobile) in the device settings or with the notification widget to enabled or disabled it, not when the device is connected or not.

I hope I explained.

cb56
 
Upvote 0
Top