jonz94 / capacitor-sim

⚡️ Capacitor plugin to get information from device's sim cards.
https://www.npmjs.com/package/@jonz94/capacitor-sim
BSD Zero Clause License
18 stars 2 forks source link

Android phones lower than 13 can't fetch phone numbers if not already set in settings. #7

Closed harshallcode closed 1 year ago

harshallcode commented 1 year ago

If the mobile number is not set in the sim card settings, the number returns an empty string. However, android 13 fetches the user's phone number properly even if the number is not set in settings.

jonz94 commented 1 year ago

Sorry for the late reply...

In some circumstances, the phone number will return an empty string, so I think this might be the excepted behavior.

For your situation, the reason why it works on Android 13 but not on Android <= 12 might be the fact that Android 13 has a newer API, which behaves differently from the API for Android <= 12.

The very detailed explanation: Why are the behaviors different on Android <= 12 and Android >= 13 - For Android >= 13, the plugin uses the [android.telephony.SubscriptionManager getPhoneNumber(subscriptionId) method](https://developer.android.com/reference/android/telephony/SubscriptionManager#getPhoneNumber(int)) under the hood to get the phone number of the device:
![image](https://github.com/jonz94/capacitor-sim/assets/16042676/9c571c6c-4415-4f72-a87d-9b692312f47a) - For Android <= 12, the plugin uses the [android.telephony.SubscriptionInfo getNumber() method](https://developer.android.com/reference/android/telephony/SubscriptionInfo#getNumber()) instead:
![image](https://user-images.githubusercontent.com/16042676/232310958-84e00d52-981b-4a3a-8067-62b75291549c.png) - In both cases, if the requirement is not met, it is possible that it will return the phone number as an empty string.

For now, I'm not 100% sure if this issue is a bug or not. I will conduct further investigation and provide more information here.

harshallcode commented 1 year ago

Thanks for the response. I also believe the new API and permissions in Android 13 must've given it access to phone numbers not found inside the setting itself.