NathanaelA / nativescript-permissions

Wraps up the entire Android 6 permissions system in a easy to use plugin.
MIT License
46 stars 22 forks source link

"no v4 support" when requesting permission #44

Closed ChristofferSkog21st closed 5 years ago

ChristofferSkog21st commented 5 years ago

We have a problem where we can't request any permissions on Android because all we get are "no v4 support" errors every time you try, there is not even a popup where you can confirm/deny access. This goes for location, phone access, you name it.

This happened without using this plugin so we thought we'd use this plugin to fix it, however the issue remains.

We are doing this:

declare var android: any;

import { requestPermission } from 'nativescript-permissions';

...
myFn() {
    requestPermission(android.Manifest.permission.CALL_PHONE, "I need these permissions because I'm cool").then(() => console.log('success')).catch((e) => console.log(e));
}

Another strange thing here is that success is being logged despite the fact that there is an error occurring when requesting permission.

What should we do to fix this?

NathanaelA commented 5 years ago

Does the demo application show this error? I have several apps using this code and haven't seen any issues...

harryt04 commented 5 years ago

I'm getting this as well.

JS: No v4 support JS: [tnsApp.suspendEvent] System.err: An uncaught Exception occurred on "main" thread. System.err: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup/3875i3719f84e0cb88b6c/136 flg=0x1 }} to activity {com.xactware.remodel/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onActivityResult failed System.err: Error: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data from pid=19944, uid=10103 requires android.permission.READ_CONTACTS, or grantUriPermission()

Testing on an android simulator (Pixel 2 XL) running Android api 28 (9.0 x86). Also we are using Nativescript v6: "tns-core-modules": "^6.1.0",.

I'm following the example in the docs exactly, other than requesting contacts.getContact() and then console logging the response, instead of performing a save on a contact.

NathanaelA commented 5 years ago

You need to make sure that your android manifest also has the permission added to it.

harryt04 commented 5 years ago

I resolved this. Seems like nativescript-permissions was somehow at least partially in scope because it is a dependency of nativescript-phone (locked to version 1.2.3). But I hadn't actually added the plugin nativescript-permissions.

I'm a little embarrassed by the rookie mistake. But after running tns pluging add nativescript-permissions, it works as I'd expect. (It pulled down v^1.3.8, which I'm assuming is the latest).

NathanaelA commented 5 years ago

Yep, the earlier versions aren't compatible with NS 6. The latest version is. :grinning: