我需要知道网络类型,但它需要权限。
我正在尝试这种方式:
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";
}
有没有办法在不需要权限的情况下获取网络类型?