Android Permissions

Hi guys, i found this thread which, at that time, shows that the only way to deal with android permissions is to manually edit the manifest file. Is there a new way to do this with 0.20? i didn’t find it on the docs.

If it doesn’t, i want to suggest it as a new feature for the upcoming versions.


Hi there!

We actually ship an undocumented android permissions api. It’s undocumented as currently it’s only available through Uno.

Here is some example code:

using Uno;
using Uno.Permissions;

public SomeClass
    public void TakePicture()
        var permissionPromise = Permissions.Request(Permissions.Android.CAMERA);
        permissionPromise.Then(OnPermitted, OnRejected);

    void OnPermitted(PlatformPermission permission)
        debug_log "Woo, we can take the picture now";

    void OnRejected(Exception e)
    {        debug_log "Damn: " + e.Message;

Permissions.Request() returns a promise, so you can then hook onto the success and failed callbacks. This works for all versions of Android.

Does this help?

[edit] Sorry I forgot to add that you will need to add Uno.Permissions to your unoproj file for this to work

Hi Chris, i’m a total noob with Android, so please correct me if i’m wrong… i know that with the last android SDK the permissions are asked at runtime, so we could use your example with Uno. But with the previous android SDK, the permissions are set in the manifest file and the user is asked when he is installing the app. We need to support older android SDKs, so, would your example work in that case?

Hi Chris,

I tried your code but I received errors

  • ‘Uno’ does not contain type or namespace ‘Permissions’. Could you be missing a package reference?
  • There is nothing named ‘PlatformPermission’ accessible in this scope. Are you missing a package reference?

I am on 0.2.20 (build 6524)

Hi, two parts.

First, the manifest issue. No problems there, on all versions of android the permissions must be in the manifest, so we do that for you. On old versions of android you will find that the ‘permitted’ callback will always be called, this gives a consistent api across all versions.

Second, seems you were missing Uno.Permissions in your unoproj, mea culpa. I will edit my previous comment and have made a gist showing a working example

Thanks for checking this out

Thanks Chris this worked fine. For those that are using a mixture of iOS and Android for this to work ensure that you wrap the request in a if defined

if defined(Android){ var permissionPromise = Permissions.Request(Permissions.Android.READ_PHONE_STATE); permissionPromise.Then(OnPermitted, OnRejected); }

Nice, glad to hear it worked.

Hi Chris,

Not working anymore with 0.28.1.

Thanks for your help wrote:

Hi Chris,

Not working anymore with 0.28.1.

Thanks for your help

Sorry, got the same error with “uno build”, but it worked with “fuse build -tandroid”.