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.
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?
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.
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); }