我需要查询数据使用的双卡双卡,使用NetworkStatsManager整个设备,因为需要报告1天的数据使用每卡。因此,我需要使用querySummaryForDevice()方法。我需要传递订阅id,我认为每个sim应该是不同的。我尝试使用这里提到的订阅管理器解决方案:Android: How to get SIM-ID of both SIMs in Android?,从这里获取订阅id将返回0字节作为使用的数据。到目前为止,我正在使用TelephonyManager获取订阅id。
发布于 2018-10-09 12:26:20
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.现在,使用反射在getSubscriberId类中调用TelephonyManager (Int)方法,并在上述步骤中获得值。此方法的返回值将是sim的订阅者id,可以在querySummaryForDevice()方法中使用它来获得该sim的数据使用情况。使用反射的代码:
Class<?> c = Class.forName("android.telephony.TelephonyManager");
Method m = c.getMethod("getSubscriberId", int.class);
Object o = m.invoke(telephonyManagerInstance, id);
subscriberId = (String) o;https://stackoverflow.com/questions/52594334
复制相似问题