[英]Geting java.lang.SecurityException: ConnectivityService: Neither user 10062 nor current process has android.permission.ACCESS_NETWORK_STATE."
Want to check Internet connection.Following is the code : 要检查Internet连接。下面是代码:
public boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
NetworkInfo networkinfo = cm.getActiveNetworkInfo();
if(networkinfo != null){
return true;
}
else {
return false;
}
}
Following is the xml file : 以下是xml文件:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.vinitmandlesha.logintestform"> <uses-permission android:name="android.permission.INTERNET"> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE" /> </uses-permission> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".sample" android:label="sample" android:theme="@style/AppTheme.NoActionBar" /> </application> </manifest>
Getting this exception on calling isNetworkConnected method.I have set all required permission in manifest file. 在调用isNetworkConnected方法时遇到此异常。我已在清单文件中设置了所有必需的权限。 Also the 3G connection is active on emulator.
3G连接也在模拟器上处于活动状态。 Where am I am going wrong ?
我要去哪里错了?
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE" />
Permission tags ending is not proper that why permissions are not being applied in the app. 权限标签结尾不正确,这就是为什么未在应用程序中应用权限的原因。
Android permissions are case sensitive, so pl change Android权限区分大小写,因此请更改
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE" />
to 至
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Try this. 尝试这个。
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
or . 要么 。
private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo() != null;
} }
I think it should be 我认为应该
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
instead of 代替
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE" />
. 。 Case sensitive.
区分大小写。
还要检查您是否在棉花糖上运行,必须为此提供动态运行时权限
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.