Applications sync data aulnmalically Manaje accounts



This value is enforced at the application level, meaning that you are responsible for reading the value and adhering to the user's preference for allowing background data transfers.

To obtain the background data setting, call the getBackgroundDataSetting method on the Connectivity Manager object:

boolean backgroundEnabled = connectivity.getBackgroundDataSetting();

If the background data setting is disabled, your application should transfer data only when it is active and in the foreground. By turning this value off, the user explicitly requests that your application not transfer data when it is not visible and in the foreground.

Prepared for ASHLEE KABAT, email: [email protected] Order number: 56760408 This PDF is for the purchaser's personal use in accordance with the Wrox Terms of Service and under US copyright as stated on this book's copyright page. If you did not purchase this copy, please visit to purchase your own copy.

If your application requires background data transfer to function, it's best practice to notify users of this requirement and offer to take them to the settings page to alter their preference.

If the user does change the background data preference, the system will send a broadcast Intent with the ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED action.

To monitor changes in the background data setting, create and register a new Broadcast Receiver that listens for this broadcast Intent, as shown in Listing 13-13.

LISTING 13-13: Accessing the Connectivity Manager Available for download on registerReceiver( new BroadcastReceiver() {

@Override public void onReceive(Context context, Intent intent) { // Do something when the background data setting changes.

}, new IntentFilter(ConnectivityManager.ACTION_BACKGROUND_DATA_SETTING_CHANGED));

While your applications are not forced to obey the user's preference for background data transfers, not doing so is likely to earn vocal criticism from users who installed your application and were rewarded with a significant mobile data bill.

Was this article helpful?

0 0
Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide

Post a comment