Book Image

Xamarin Mobile Application Development for Android, Second Edition

Book Image

Xamarin Mobile Application Development for Android, Second Edition

Overview of this book

Table of Contents (18 chapters)
Xamarin Mobile Application Development for Android Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling no network condition


The network conditions in mobile devices are uncertain. Sometimes, a user manually disables the network connections or they are unavailable due to various external reasons. For applications that use network data, you must handle different network states. Applications should react gracefully by showing an appropriate message to the user.

In POIApp, before starting the download, we must confirm the availability of the network data connections. If the network is unavailable, we should notify the user with an appropriate message otherwise continue with the download request.

The ConnectivityManager class present in the System.Net package can be used to query the state of device network connectivity. This class can also be used to monitor the network connection and notify when there is a change in the network state. In our case, we will just query the network information just to know that the network is available.

Accessing the network state using the ConnectivityManager...