Reader small image

You're reading from  Cross-platform UI Development with Xamarin.Forms

Product typeBook
Published inAug 2015
Reading LevelBeginner
Publisher
ISBN-139781784391195
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Paul Johnson
Paul Johnson
author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson

Right arrow

Setting up your Android code


Setting up the connectivity code in Android is a two-step procedure:

  1. The first is the creation of BroadcastReceiver.

  2. 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...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Cross-platform UI Development with Xamarin.Forms
Published in: Aug 2015Publisher: ISBN-13: 9781784391195

Author (1)

author image
Paul Johnson

Paul Johnson has been writing software since the early 1980s on machines ranging from the ZX81 and servers to his trusty Mac, and has used more languages than he can remember. He is a qualified scuba diver and college lecturer. Paul lives with his wife, kids, and pets, and listens to an inordinate amount of rock and metal on Primordial Radio. This is his third book for Packt.
Read more about Paul Johnson