hel*_*ind 2 java android android-service
在服务中我正在使用以下功能来验证互联网连接:
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
return !(networkInfo == null || !networkInfo.isConnected());
}
Run Code Online (Sandbox Code Playgroud)
问题是,如果我没有Internet连接,我在日志中获得以下内容:
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
Run Code Online (Sandbox Code Playgroud)
所以Android 5.1.1告诉我,我的应用程序正在减慢我的设备,并且始终存在错误.
有什么问题?谢谢.
Tis是用于检查Internet连接的函数.
public boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo networkinfo = cm.getActiveNetworkInfo();
if (networkinfo != null && networkinfo.isConnected()) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9070 次 |
| 最近记录: |