How to toggle the option returned by ConnectivityManager.getBackgroundDataSetting()?
Did anybody watch jsharkey's battery life google io presentation ?
How does one toggle the option returned by ConnectivityManager.getBackgroundDataSetting(开发者_开发问答)
in the emulator ?
The short answer is you can't.
The longer answer is you shouldn't. It is one of the secure settings, and as such shouldn't be manipulated directly.
The docs in the link above state:
Secure system settings, containing system preferences that applications can read but are not allowed to write. These are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.
The easiest way to do this is to point the user to the correct settings activity, using the SYNC_SETTINGS
action:
Intent intent = new Intent("android.settings.SYNC_SETTINGS");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
This is most likely to break the flow of your app, but will make sure the user is aware of the change to the settings.
精彩评论