我有這個完全相同的問題,我不得不開始賞金來得到答案。花費我三分之一的聲譽,但非常值得。
boolean mobileDataEnabled = false; // Assume disabled
ConnectivityManager cm1 = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
Class cmClass = Class.forName(cm1.getClass().getName());
Method method = cmClass.getDeclaredMethod("getMobileDataEnabled");
method.setAccessible(true); // Make the method callable
// get the setting for "mobile data"
mobileDataEnabled = (Boolean)method.invoke(cm1);
} catch (Exception e) {
// Some problem accessible private API
// TODO do whatever error handling you want here
}
正如我說的,我不能居功知道這一點,我的問題是由https://stackoverflow.com/users/769265/david-wasser
回答,但我的成本,所以如果你想接受這個作爲一個答案,我可以開始讓我我的一些聲望點回來了! :)
謝謝!這回答了我的問題的一部分。與此同時,我已升級到果凍豆,在這裏谷歌已從同步菜單中刪除背景數據: - /無論如何 - 我接受了你的答案,因爲它解決了我在JB上的問題。 –
啊,對,我沒有意識到分組數據和同步數據是不同的設置。我推測這是說同一件事的兩種不同方式。似乎可以使用與上面相同的方法來檢查此問題。我會檢查出來,如果我解決了問題,請回復你! –
我碰到這個答案似乎回答你的問題的其他部分:http://stackoverflow.com/questions/8996327/how-to-enable-the-background-data-settings-in-android –