Using multiple TelephonyManagers with multi-sim device

Mobile Technologies Mobile Computing 2 years ago

2 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I am trying to establish whenever a multisim Android device (running Android 7.0+) has any working/enabled sim cards. For this I am following Google's documentation regarding attaching multiple TelephonyManagers to the default TelephonyManager instance, as per : https://developer.android.com/reference/android/telephony/TelephonyManager.html#SIM_STATE_READY The returned TelephonyManager will use the default subscription for all calls. To call an API for a specific subscription, use createForSubscriptionId(int). e.g. telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); In my specific case something like this : telephonyManager = (TelephonyManager) mContext .getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_SERVICE_STATE); List subList = mSubManager.getActiveSubscriptionInfoList(); SubscriptionInfo firstSub = (SubscriptionInfo) subList.get(0); mSim0TelephonyManager = telephonyManager.createForSubscriptionId(firstSub.getSubscriptionId()); mSim0TelephonyManager.listen(new Sim0PhoneStateListener(), PhoneStateListener.LISTEN_SERVICE_STATE); int test = mSim0TelephonyManager.getSimState(); SubscriptionInfo secondSub = (SubscriptionInfo) subList.get(1); mSim1TelephonyManager = telephonyManager.createForSubscriptionId(secondSub.getSubscriptionId()); mSim1TelephonyManager.listen(new Sim1PhoneStateListener(), PhoneStateListener.LISTEN_SERVICE_STATE); int testw = mSim1TelephonyManager.getSimState(); So first I get all active subscriptions ,which was already a pain because in reality those are not active subscriptions as in subscriptions who have state in service, those are simply the SIM cards inserted into the SIM slots. Which means that even if you deactivate a SIM card using the Android Settings Menu you will still receive that SIM card as being an active subscription !!!! The next problem is that even on deactivated (No service!!!) SIM cards I am getting a value 5 (https://developer.android.com/reference/android/telephony/TelephonyManager.html#SIM_STATE_READY). For me this is incomprehensible, the SIM state is ready whilst the whole SIM is deactivated. This means those API calls are not reliable at all... Also after adding the PhoneStateListeners to the individual new TelephonyManagers I am not getting any calls to the implementations of those PhoneStateListeners when the SIM cards are activates/deactivated through the Android Settings Menu... Now I am wondering if something is broke within Android, or maybe with the device manufacturers implementations (testing on a Samsung A5 2017 Duo and a Huawei P9 Lite). Unfortunately the emulator does not support multi-sim so I cannot test the plain vanilla Android Nougat version on that :( UPDATE : In the meantime I found this topic : How to get a PhoneStateListener when using Dual SIM functionality It would seem there is actually a bug within Google's implementation within listen(PhoneStateListener listener, int events) which results in a PhoneStateListener being instantiated only for the default SubscriptionId independently from the parameter which is being passed in the constructor....

Posted on 30 Aug 2022, this text provides information on Mobile Computing related to Mobile Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ I didn't try but it might work for you subids[] = SubscriptionManager.getSubscriptionId() if (SubscriptionManager.isActiveSubscriptionId(subids[0])){ mSim0TelephonyManager = telephonyManager.createForSubscriptionId(firstSub.getSubscriptionId()); } this will work

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Mobile Technologies Links