2
Fragmet中CONNECTIVITY_SERVICE的上下文是什麼,我也檢查過getActivity,但它給出錯誤。Fragment中CONNECTIVITY_SERVICE的上下文是什麼?
public boolean isOnline() {
ConnectivityManager connectionManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
try {
if (connectionManager.getActiveNetworkInfo().isConnected()) {
Log.d("ConStatus", "Data Connection On");
return true;
} else {
Log.d("ConStatus", "Data Connection off");
return false;
}
} catch (NullPointerException e) {
Log.i("ConStatus", "No Active Connection");
return false;
}
}
你能提供的堆棧跟蹤,當你使用getActivity? – Darwind
我寫了getSystemService(getActivity()。CONNECTIVITY_SERVICE);並在那裏它自我給出一個錯誤,請創建一個方法getSystemService。 – user1744952