0

Does anyone know if there is a way to programmatically obtain the Network Notification setting on an Android device? This setting is what allows a user to be notified (or not) when a network is available. I simply need to retrieve the current value, not set it.

I have checked ConnectivityManager and also perused objects like WifiInfo and haven't seen anything that appears too useful. Thanks for any guidance.

blh83
  • 495
  • 5
  • 17

1 Answers1

0

You should make a broadcast receiver that will be triggered when a new network is availible by adding this to your manifest.

<receiver
    android:name=".receivers.NetworkChangeReceiver"
    android:label="NetworkChangeReceiver">
    <intent-filter>
        <action
            android:name="android.net.conn.CONNECTIVITY_CHANGE" />
        <action
            android:name="android.net.wifi.WIFI_STATE_CHANGED" />
    </intent-filter>
</receiver>

And then in your receiver you can check if there is connectivity.

public class NetworkChangeReceiver extends BroadcastReceiver{

   @Override
   public void onReceive(Context context, Intent intent) {
   ConnectivityManager cm=(ConnectivityManager)  context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if(cm.getActiveNetworkInfo()!=null&&cm.getActiveNetworkInfo().isConnected()){
       //Send a broadcast to your service or activity that you have network or notifiy you have a network 
       //...
   }else{
       LOG.i("Network UNAVAILABLE");
   }
 }

}

coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118
  • Thank you for taking time to reply. Unfortunately I don't thin I was all that clear. What I am hoping to find out from the device is whether or not a user has chosen to receive notifications of new networks. Basically, I simply want to know if a user has checked the checkbox in their settings menu to be notified when a new network is available. If they have not chosen to be notified, then to connect to a network, they must do so explicitly through their WiFi menu. Does this make sense? – blh83 Jan 15 '12 at 05:34
  • @blh83 have managed to find this? I'm looking for the same thing. – George Apr 04 '16 at 15:43