0
我需要知道網絡類型,但它需要權限。不需要權限就可以獲得網絡類型(wifi/mobile)嗎?
我想是這樣的:
public String getConnectionTypeNew(Context context){
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork != null) { // connected to the internet
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
return "WiFi Network";
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
return "Mobile Network";
}
}
return "No Network";
}
有沒有辦法讓網絡類型,而無需權限?
感謝
ACCESS_NETWORK_STATE不是危險權限。你爲什麼試圖繞過它? – DeeV