Setting up your Android code
Setting up the connectivity code in Android is a two-step procedure:
The first is the creation of
BroadcastReceiver
.The second is calling this receiver into being.
Broadcast whatcha-ma-call-it?
When something happens on the hardware level, Android broadcasts a message that any code can listen to. In order to listen to the message, a broadcast receiver is used. In the case of the connectivity broadcast receiver, the code is simple enough:
[BroadcastReceiver] public class Connectivity : BroadcastReceiver { public override void OnReceive(Context context, Intent intent) { var extras = intent.Extras; using (var info = extras.GetParcelable("networkInfo") as NetworkInfo) { var state = info.GetState(); var result = state == NetworkInfo.State.Connected || state == NetworkInfo.State.Connecting; // store the online state in the internal settings system ConfigUtils.SaveSetting("online", result, SettingType.Bool...