firescript / nativescript-contacts

A nativescript module that gives access to the native contact directory.
MIT License
28 stars 32 forks source link

Permission error on android even though permission is set on manifest file. #23

Closed nicolam1 closed 7 years ago

nicolam1 commented 7 years ago

I'm getting the following error on android: JS: Error: Error: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{258e81c 3198:com.ink.application/u0a90} (pid=3198, uid=10090) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS

Though I've set the permission on AndroidManifest.xml as:

<uses-permission android:name="android.permission.READ_CONTACTS" />
  <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />

I'm using this within a angular app. Does it matter? The code that accesses the contact is here:

    let contacts = require( 'nativescript-contacts' );
    contacts.getAllContacts().then((contacts) => {
      contacts.data.forEach((contact) => {
        let name = contact.name.given + ' ' + contact.name.family;
        let phones = contact.phoneNumbers.map((phoneNumber) => {
          return phoneNumber.value;
        });
        this.contactsList.push({ name, phones });
      });
    },
    (err) => {
      console.log('Error: ' + err);
    });
nicolam1 commented 7 years ago

FYI If I do go to settings/apps/myapp/permissions and grant contact access it works fine. I guess the question is why are we not getting prompt for accessing contacts?

nicolam1 commented 7 years ago

using the permission script as suggested on a different issue