Android Internet permission in Unity

2020-03-21 10:28发布

It seems like by default Unity doesn't put

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

to generated AndroidManifest.xml. These permissions are required in my project. Google doesn't give me direct answer. Is it possible?

1条回答
家丑人穷心不美
2楼-- · 2020-03-21 10:45

Go to Edit->Project Settings -> Player. Select Android, Build Settings, Change Internet Access from Auto to Require. You don't have to do this because Unity will do for automatically when you use any network API.

enter image description here

If that's not enough for you then you can modify the Android AndroidManifest by hand.

1. Open Unity. Build your project for Android just once. Don't close it.

2. Go to your Project Directory. A new Folder called Temp will be created by Unity after step 1. Inside that Temp there is another Folder called StagingArea. Go into the StagingArea folder and copy a file called AndroidManifest.xml into another folder in your computer. Modify/Add your own custom permission like the ones in your question.

3. Now move that modified AndroidManifest.xml file to Your Project Directory->Assets->Plugins->Android. If the Plugins and the Android Folders does not exit, create them.

Enjoy!

查看更多
登录 后发表回答