roblav96 / nativescript-telephony

A Nativescript plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
Other
22 stars 9 forks source link

Permission errors with {N} 6 #14

Open dlcole opened 4 years ago

dlcole commented 4 years ago

I updated my project to NativeScript 6 and also updated Android Studio. Now, on both emulators and real devices, I get permission errors when I invoke telephony():

`JS: nativeException: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10089 nor current process has android.permission.READ_PHONE_STATE, android.permission.READ_SMS, or android.permission.READ_PHONE_NUMBERS`

Adding the permissions to my own AndroidManifest.xml makes no difference. And, Google Play has a recent policy that restricts READ_SMS to apps that can act as the default text app.

I realize this repository hasn't been active recently but I'm hoping for some insight.

bachras commented 4 years ago

@dlcole Have you managed to solve the problem or found any workaround? I have same problem

dlcole commented 4 years ago

@bachras Unfortunately I have not. As far as I can tell, this plug-in is abandoned and simply does not work on NativeScript 6.0 or later. If you find that's not the case, please post here.

dosomder commented 4 years ago

It works fine but you have to request permission with https://github.com/NathanaelA/nativescript-permissions.

Something like this:

setTimeout(function() {
      permissions
        .requestPermission(
          android.Manifest.permission.READ_PHONE_STATE,
          "I need these permissions because I'm cool"
        )
        .then(() => {
          console.log("Woo Hoo, I have the power!");
          Telephony()
            .then(function(resolved) {
              console.log("resolved >", resolved);
              console.dir(resolved);
            })
            .catch(function(error) {
              console.error("error >", error);
              console.dir(error);
            });
        })
        .catch(() => {
          console.log("Uh oh, no permissions - plan B time!");
        });
    }, 100);