Set Permissions
Adding Permissions
To request a permisison you must firstly have added these permissions you require to your application's manifest.
Permissions are represented with a tag like the following:
<uses-permission android:name="android.permission.CAMERA" />
A complete list of the possible permissions is found here.
- APM
- Manual
- Unity
To add these permissions you need to add some additional configuration to apm. Firstly add a custom Android configuration file by running:
apm generate config android
Edit the config/android/AndroidManifest.xml
file that was generated to resemble the following, adding the required permissions, eg:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CAMERA" />
</manifest>
You can add any other additions you require in your application here and these will be merged by apm
when you generate your application descriptor.
Make sure you regenerate your application descriptor after modifying this file. See the section in add the extension for details.
To manually add permissions to your application, you will need to edit the manifest additions node in your application descriptor. For example, to add the camera permission:
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<!-- PERMISSIONS -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- OTHER MANIFEST ADDITIONS -->
</manifest>
]]></manifestAdditions>
</android>
There are several methods to add entries to the android manifest in Unity. If you already have a preferred approach, you can simply add the permissions you require to your manifest, eg:
<uses-permission android:name="android.permission.CAMERA" />
The approach we prefer is to create a folder in your Assets
folder something like Project.androidlib
, (you can create this in a subfolder like Plugins/Android
to keep things organised).
Create a file in this directory called project.properties
and add the following contents:
android.library=true
Then create an AndroidManifests.xml
file and add the additions you need:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="project.packagename.resources">
<uses-permission android:name="android.permission.CAMERA" />
</manifest>
Unity will merge the contents of this file into your applications manifest during a build.