简体   繁体   English

检测双SIM卡移动设备中的当前/主SIM卡

[英]Detect the current/ primary SIM in Dual SIM mobile

I have a dual SIM mobile on which my app displays the details of the SIM and operator. 我有一个双SIM卡手机,我的应用程序显示SIM和操作员的详细信息。 But (obviously) it detects and shows details of only SIM1 and not SIM2. 但(显然)它检测并显示只有SIM1而不是SIM2的细节。 Is there a way in which SIM2 details can be accessed? 有没有办法可以访问SIM2的详细信息?

I know that Android does not support dual SIM by default and that the mobile manufacturer tweaks it in such a way that Android uses the selected SIM (SIM1 or SIM2, whichever user selects) as primary (for making a call) and the other SIM is standby (kicks in when a call is received). 我知道默认情况下Android不支持双SIM卡,而且移动设备制造商调整它的方式是Android使用所选的 SIM(SIM1或SIM2,无论用户选择哪个)作为主要(用于拨打电话)而另一个SIM卡是待机(收到来电时启动)。 There has to be a way to detect this primary SIM. 必须有一种方法来检测这个主SIM卡。

I am not interested in fetching both SIM details at the same time. 我对同时获取两个SIM详细信息不感兴趣。 Only require details of the SIM that has been selected by user as primary for making calls. 仅需要用户选择作为主要拨打电话的SIM的详细信息。

Any link/ working example/ suggestions, any sort of help would be highly appreciated. 任何链接/工作示例/建议,任何形式的帮助将受到高度赞赏。

Thanks 谢谢

To see state of SIM1 type in console: adb shell dumpsys telephony.registry 要在控制台中查看SIM1类型的状态:adb shell dumpsys telephony.registry

To see state of SIM2 type in console: adb shell dumpsys telephony.registry2 要在控制台中查看SIM2类型的状态:adb shell dumpsys telephony.registry2

mCallState changed on incoming/outgoing call. 传入/传出呼叫时mCallState已更改。 It allow to let you know which SIM card used for call 它可以让您知道哪个SIM卡用于通话

To see some additional info: adb shell getprop|grep gsm 要查看其他一些信息:adb shell getprop | grep gsm

When you invoke dumpsys from Java-application, you need android.permission.DUMP in manifest. 从Java应用程序调用dumpsys时,清单中需要android.permission.DUMP。 But it not works on some new devices. 但它不适用于某些新设备。

On some phones can work this code to know the default sim card : 在某些手机上可以使用此代码来了解默认的SIM卡

Object tm = getSystemService(Context.TELEPHONY_SERVICE);
Method method_getDefaultSim;    
int defaultSim = -1;
try {
    method_getDefaultSim = tm.getClass().getDeclaredMethod("getDefaultSim");
    method_getDefaultSim.setAccessible(true);
    defaultSim = (Integer) method_getDefaultSim.invoke(tm);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Method method_getSmsDefaultSim;
int smsDefaultSim = -1;
try {
    method_getSmsDefaultSim = tm.getClass().getDeclaredMethod("getSmsDefaultSim");
    smsDefaultSim = (Integer) method_getSmsDefaultSim.invoke(tm);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Step #1: Make a list of every Android device manufacturer that has 1+ dual-SIM devices. 步骤1:列出每个拥有1个以上双SIM卡设备的Android设备制造商。

Step #2: Contact those manufacturers and ask your questions of them. 步骤2:联系这些制造商并询问他们的问题。

As you wrote: 正如你写的:

I know that Android does not support dual SIM by default and that the mobile manufacturer tweaks it 我知道默认情况下Android不支持双SIM卡,移动设备制造商会调整它

There is no requirement that any given device manufacturer must tweak it the same way as does any other manufacturer, and there is no requirement that any given device manufacturer must tweak it in a way that is visible to an app developer. 不要求任何给定的设备制造商必须以与任何其他制造商相同的方式调整它,并且不要求任何给定的设备制造商必须以应用开发者可见的方式调整它。 Hence, the only way to get the information you desire, if app support is actually available, is to contact the manufacturer. 因此,如果实际可以获得应用程序支持,获取所需信息的唯一方法是联系制造商。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM