我想将我的应用程序连接到互联网,所以我输入了连接到互联网和访问网络状态的权限检查:
    
    

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MovieManiac">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<user-permission android:name="android.permission.INTERNET"/>
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>


我尝试了以前发布的所有解决方案,例如再次添加用户权限,并且还进行了干净的构建,但似乎无济于事。我使用API​​22。我非常感谢您的帮助。我得到的错误是:

FATAL EXCEPTION: main
Process: com.example.archit.moviemaniac, PID: 4638
java.lang.SecurityException: ConnectivityService: Neither user 10105 nor current process has android.permission.ACCESS_NETWORK_STATE.
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:964)
at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:610)
at com.example.archit.moviemaniac.MovieManiac$1.onClick(MovieManiac.java:41)
at android.view.View.performClick(View.java:4789)
at android.view.View$PerformClick.run(View.java:19881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

最佳答案

更换

<user-permission android:name="android.permission.INTERNET"/>
<user-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>




<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


在Android清单中,您正在使用user-permission而不是uses-permission。

09-03 17:36