我写了func to chek internet conection,但是我在这个针脚java.lang.SecurityException
NetworkInfo netInfo = cm.getActiveNetworkInfo();
public static boolean isOnline()
{
ConnectivityManager cm =
(ConnectivityManager) MainActivity.sContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting())
{
return true;
}
return false;
}
答案 0 :(得分:0)
您是否已经向您的Manifest添加了检查网络状态的权限?
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />