Android Internet permission in Unity

25,361

Solution 1

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!

Solution 2

People that is using Unity 2019.3 or newer... (docs.unity3d.com/Manual/android-manifest.html)

Don't know if it's correct what I've done but it worked.

I added the permisions in the AndroidManifest doing this:

Following the steps of @Programmer but in the step 2 instead of going to the StagingArea folder I went to YourUnityProject\Temp\gradleOut\unityLibrary\src\main -> AndroidManifest.xml

Also I deleted a extra "-" before "<manifest xmls..." Don't know if you will have this error too.

Share:
25,361
DeepThought
Author by

DeepThought

Updated on August 22, 2022

Comments

  • DeepThought
    DeepThought over 1 year

    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?

  • DeepThought
    DeepThought almost 8 years
    Brilliant! thanks for first method, I don't know why google haven't led me to some official documentation. the second solution is a bit more complicated, and actually until now I was using it, except one thing: I was picking AndroidManifest from another place - from /Applications/Unity/PlaybackEngines/AndroidPlayer/Apk/Androi‌​dManifest.xml (this is on OS X environment)
  • Programmer
    Programmer almost 8 years
    @DeepThought Unity don't document some stuff. I suggest you master the second solution. You will need it when making your own plugins, if there is Manifest conflict or if you want a permission that is not available in Unity. You should get used to it if you do it 3 or 5 times. It's only copying file, modifying it and putting into into another directory.
  • Morten Nørgaard
    Morten Nørgaard over 3 years
    AndroidManifest.xml is no longer present in the StagingArea-folder. Unity documentation about manifest-files, as of Nov-2020, docs.unity3d.com/Manual/android-manifest.html