我想检查用户是否在他/她的设备上启用了背景数据,并在禁用时显示消息。
如何检查是否已启用? 我试过了
import android.provider.Settings;
//...
Settings.System.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);
//and
Settings.Secure.getString(getContentResolver(), Settings.Secure.BACKGROUND_DATA);
但他们正在返回null。
谢谢你, 的政绩。
答案 0 :(得分:10)
您想使用Connectivity Manager获取此信息。
ConnectivityManager mgr = (ConnectivityManager)Context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean bgData = mgr.getBackgroundDataSetting();