如何检查是否后台数据是在Android启用? [英] How to check if background data is enabled on the android?

查看:206
本文介绍了如何检查是否后台数据是在Android启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查,如果用户启用背景资料他/她的设备上,如果它被禁用显示一条消息。

我如何检查是否已启用? 我试过

 进口android.provider.Settings;

// ...
Settings.System.getString(getContentResolver(),Settings.Secure.BACKGROUND_DATA);
//和
Settings.Secure.getString(getContentResolver(),Settings.Secure.BACKGROUND_DATA);
 

但他们返回null。

感谢您, Achie。

解决方案

您想要使用的<一个href="http://developer.android.com/intl/de/reference/android/net/ConnectivityManager.html">Connectivity管理器得到这个信息。

  ConnectivityManager经理=(ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE);
布尔bgData =经理。<一个href="http://developer.android.com/intl/de/reference/android/net/ConnectivityManager.html#getBackgroundDataSetting%28%29">getBackgroundDataSetting();

I want to check if the user enabled background data on his/her device and display a message if it is disabled.

How can I check if it has been enabled? I tried

import android.provider.Settings;

//...
Settings.System.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);
//and
Settings.Secure.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);

But they are returning null.

Thank you, Achie.

解决方案

You want to use the Connectivity Manager to get this info.

ConnectivityManager mgr = (ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean bgData = mgr.getBackgroundDataSetting();

这篇关于如何检查是否后台数据是在Android启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆