I need to query data usage for both the sim cards in dual sim mobile phones using NetworkStatsManager for entire device as need to report 1 day data usage for each sim card. Hence, I need to use the method querySummaryForDevice(). I need to pass subscription id which I believe should be different for each sim. I tried using Subscription Manager solution mentioned here:Android: How to get SIM-ID of both SIMs in Android? Somehow, getting subscription id from here returns 0 bytes as data used. As of now I am using TelephonyManager to get the subscription id.
Asked
Active
Viewed 365 times
1 Answers
2
SubscriptionManager subscriptionManager = (SubscriptionManager) ControlApplication.getControlApplicationContext().getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
int id = subInfoList.get(i). getSubscriptionId();
//Here, i is index in the list.
Now use reflection to invoke getSubscriberId(int) method in TelephonyManager class with value obtained in above step. Return value for this method will be required subscriber id for the sim which could be used in querySummaryForDevice() method to obtain data usage for that sim. Code using reflection:
Class<?> c = Class.forName("android.telephony.TelephonyManager");
Method m = c.getMethod("getSubscriberId", int.class);
Object o = m.invoke(telephonyManagerInstance, id);
subscriberId = (String) o;

Deepti
- 138
- 1
- 8
-
Hi, even i am facing the same issue, i am able to get the id as you mentioned above, But there is no getSubscriberId(int) method in TelephonyManager class, can you explain a bit more how you got it. – Basha K Nov 10 '18 at 05:27
-
1You need to use reflection to invoke that method. Its not accessible otherwise. – Deepti Nov 21 '18 at 11:23