pbakondy / cordova-plugin-sim

:cherries: A cordova plugin to get the device's SIM data (carrier name, mcc mnc, country code, telephonenumber, etc)
MIT License
163 stars 100 forks source link

android.permission.READ_SMS permission error #21

Closed 1N50MN14 closed 8 years ago

1N50MN14 commented 8 years ago

Expected behaviour

This error should not be thrown, plugin should not have READ_SMS permission dependency.

Actual behaviour

getLine1NumberForDisplay: Neither user 10157 nor current process has android.permission.READ_SMS error is thrown, no sim data returned.

I'm seeing this behaviour on

Remove this hint: these checkboxes can be checked like this: [x]

Nexus 5

OS versions

Android 6.0.1

I've checked these

Simply run on Android 6.0.1

pbakondy commented 8 years ago

What do you mean "the plugin should not have READ_SMS permission dependency"?

1N50MN14 commented 8 years ago

@pbakondy My understanding is that READ_PHONE_STATE is the only permission required for the plugin to successfully work. For some reason the plugin throws READ_SMS permission error on Cordova 6.0.0 and Android 6.0.1. This was not the case when I ran the plugin with Cordova 5.4.0, I started seeing this error after upgrading.

pbakondy commented 8 years ago

OK, I get it. This error message can be misleading.

getLine1Number() method requires permission READ_PHONE_STATE or READ_SMS. The error message references only the second one.

http://developer.android.com/reference/android/telephony/TelephonyManager.html#getLine1Number%28%29

Please upgrade to the latest version of cordova-plugin-sim and test again.

1N50MN14 commented 8 years ago

Yup, thank you that did it! The one thing I noticed is the phoneNumber attribute is now missing in the callback object, I'm not sure if this is related to upgrading to Android 6.0.0, in which case isn't it supposed to be an empty string?

pbakondy commented 8 years ago

https://github.com/pbakondy/cordova-plugin-sim#android-60-permissions

1N50MN14 commented 8 years ago

3,2,1 slap on my face! I'm usually careful going through README I should've revisited that. Closing issue, thanks for the help ;)

AndroidDeveloperLB commented 8 years ago

@pbakondy Just found this post by searching on the internet for this issue (not using the repo), and I'd like to correct you: On Android 5.x and below, you must have READ_PHONE_STATE permission to call getLine1Number, but from Android 6.x it seems it needs either READ_PHONE_STATE or READ_SMS. I suggest using only READ_PHONE_STATE, because I don't see any docs about this weird behavior. Also, I've published a post about it here: https://code.google.com/p/android/issues/detail?id=226748