- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我知道我们可以使用 TelephonyManager 类检索单个 Sim 卡的信息。但是如何检索有关多张 SIM 卡的信息?比如说,我的手机丢了,有人更换了其中一个插槽中的 SIM 卡。我如何收到包括 IMEI 号码、电话号码等在内的信息?我只在更换 Sim 卡时才需要这些信息。
在 TelephonyManager 类中,有直接方法可以检索这些信息(如 IMEI 号码、电话号码、电话网络类型等),但这些信息仅适用于一张 Sim 卡。我如何接收有关多张 SIM 卡的所有信息。P.S-SubscriptionManager 类没有像 TelephonyManager 类那样的直接方法。
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.widget.TextView;
import java.util.List;
import static android.R.id.content;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int subID,simposition,content;
String carrier,number;
TextView textView2=(TextView)findViewById(R.id.text);
SubscriptionManager subManager=(SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subInfoList=subManager.getActiveSubscriptionInfoList();
for(int i=0;i<subInfoList.size();i++)
{
subID = subInfoList.get(i).getSubscriptionId();
simposition = subInfoList.get(i).getSimSlotIndex();
content=subInfoList.get(i).describeContents();
carrier= (String) subInfoList.get(i).getCarrierName();
number= subInfoList.get(i).getNumber();
}
/* String info2="Sim Details:\n";
info2+="\n SubId:"+subID;
info2+="\n Sim position:"+simposition;
info2+="\n contents:"+content;
info2+="\n carrier:"+carrier;
info2+="\n number:"+number;
textView2.setText(info2);*/
}
}
最佳答案
您可以使用此工作示例代码来解决您的问题。
引用链接:https://github.com/ITger/DualSIMCard
/**
* Created by piotrz on 7/23/15.
* Copyright 2015 Piotr Zerynger ITger
*/
import android.content.Context;
import android.telephony.CellInfo;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static pl.itger.dualsimcard.MainActivity.getMActContext;
public final class TelInfo {
private static TelInfo telInf;
protected Sci[] scitems;
ArrayList<Sci> scitemsArr;
//private String imsiSIM1;
private String imsiSIM2;
private boolean isSIM1Ready;
private boolean isSIM2Ready;
private String sim1_STATE;
private String sim2_STATE;
// Integrated circuit card identifier (ICCID)
private String sim1_ICCID;
private String sim2_ICCID;
// International mobile subscriber identity (IMSI)
private String sim1_IMSI;
private String sim2_IMSI;
// Service provider name (SPN)
private String sim1_SPN;
private String sim2_SPN;
// Mobile country code (MCC)
private String sim1_MCC;
private String sim2_MCC;
// Mobile network code (MNC)
private String sim1_MNC;
private String sim2_MNC;
//private NeighboringCellInfo nci;
//private List<NeighboringCellInfo> sim1_NC;
//private List<NeighboringCellInfo> sim2_NC;
private String sim1_MCC_MNC;
private String sim2_MCC_MNC;
// Mobile subscriber identification number (MSIN)
// Mobile station international subscriber directory number (MSISDN)
private String sim1_MSISDN;
private String sim2_MSISDN;
// Abbreviated dialing numbers (ADN)
// Last dialed numbers (LDN)
// Short message service (SMS)
// Language preference (LP)
// Card holder verification (CHV1 and CHV2)
// Ciphering key (Kc)
// Ciphering key sequence number
// Emergency call code
// Fixed dialing numbers (FDN)
//getDeviceId() Returns the unique device ID, for example, the IMEI for GSM and the MEID or ESN for CDMA phones.
private String sim1_IMEI;
private String sim2_IMEI;
// Local area identity (LAI)
private String sim1_LAI;
private String sim2_LAI;
// Location Area Code (LAC).
private String sim1_LAC;
private String sim2_LAC;
// Own dialing number
// Temporary mobile subscriber identity (TMSI)
// Routing area identifier (RIA) network code
// Service dialing numbers (SDNs)
// CellID
private String sim1_CellID;
private String sim2_CellID;
private List<CellInfo> all;
private TelInfo() {
}
/*@
@requires context != null;
@ensures TelInfo != null;
@*/
public static TelInfo getInstance() {//Context context) {
//if (TelInfo.telInf != null) {
TelInfo.telInf = null;
TelInfo.telInf = new TelInfo();
//}
Context context = getMActContext();
//printTelephonyManagerMethodNamesForThisDevice(context);
//System.out.println("1 " + context);
TelephonyManager telMngr = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE));
//System.out.println("2 " + telMngr);
//telInf.nci = new NeighboringCellInfo(NeighboringCellInfo.UNKNOWN_RSSI, new GsmCellLocation().toString(), TelephonyManager.NETWORK_TYPE_HSPA);
//System.out.println(telInf.nci.toString());
telInf.sim1_ICCID = telMngr.getSimSerialNumber();
telInf.sim1_IMSI = telMngr.getSubscriberId();
telInf.sim1_SPN = telMngr.getSimOperatorName();
telInf.sim1_MCC = telMngr.getNetworkCountryIso();
telInf.sim1_MNC = telMngr.getNetworkOperatorName();
telInf.sim1_MCC_MNC = telMngr.getSimOperator();
telInf.sim1_MSISDN = telMngr.getLine1Number();
telInf.sim1_IMEI = telMngr.getDeviceId();
//telInf.sim1_NC = telMngr.getNeighboringCellInfo();
if (telMngr.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = (GsmCellLocation) telMngr.getCellLocation();
if (location != null) {
telInf.sim1_LAC = Integer.toString(location.getLac());
telInf.sim1_CellID = Integer.toString(location.getCid());
}
}
telInf.imsiSIM2 = null;
telInf.isSIM1Ready = telMngr.getSimState() == TelephonyManager.SIM_STATE_READY;
telInf.isSIM2Ready = false;
telInf.sim1_STATE = simState(telMngr.getSimState());
try {
//telInf.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
telInf.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
//System.out.println("!!");
} catch (ITgerMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
if (telInf.isSIM2Ready) {
try {
// telInf.sim1_IMSI = getDeviceIdBySlot(context, "getDeviceId", 0);
telInf.imsiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
telInf.sim2_ICCID = getDeviceIdBySlot(context, "getSimSerialNumber", 1);
telInf.sim2_IMSI = getDeviceIdBySlot(context, "getSubscriberId", 1);
telInf.sim2_SPN = getDeviceIdBySlot(context, "getSimOperatorName", 1);
telInf.sim2_MCC = getDeviceIdBySlot(context, "getNetworkCountryIso", 1);
telInf.sim2_MNC = getDeviceIdBySlot(context, "getNetworkOperatorName", 1);
telInf.sim2_MCC_MNC = getDeviceIdBySlot(context, "getSimOperator", 1);
telInf.sim2_MSISDN = getDeviceIdBySlot(context, "getLine1Number", 1);
telInf.sim2_IMEI = getDeviceIdBySlot(context, "getDeviceId", 1);
if (telMngr.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
final GsmCellLocation location = getCellLocBySlot(context, "getCellLocation", 1);// telMngr.getCellLocation();
if (location != null) {
telInf.sim2_LAC = Integer.toString(location.getLac());
telInf.sim2_CellID = Integer.toString(location.getCid());
}
}
System.out.println("!");
} catch (ITgerMethodNotFoundException e1) {
//Call here for next manufacturer's predicted method name if you wish
e1.printStackTrace();
}
}
telInf.scitemsArr = new ArrayList<Sci>();
telInf.scitemsArr.add(new Sci("SIM 1 state", telInf.sim1_STATE));
telInf.scitemsArr.add(new Sci("Integrated circuit card identifier (ICCID)", telInf.sim1_ICCID));
telInf.scitemsArr.add(new Sci("Unique device ID (IMEI or MEID/ESN for CDMA)", telInf.sim1_IMEI));
telInf.scitemsArr.add(new Sci("International mobile subscriber identity (IMSI)", telInf.sim1_IMSI));
telInf.scitemsArr.add(new Sci("Service provider name (SPN)", telInf.sim1_SPN));
telInf.scitemsArr.add(new Sci("Mobile country code (MCC)", telInf.sim1_MCC));
telInf.scitemsArr.add(new Sci("Mobile operator name", telInf.sim1_MNC));
telInf.scitemsArr.add(new Sci("Mobile country code + mobile network code (MCC+MNC)", telInf.sim1_MCC_MNC));
telInf.scitemsArr.add(new Sci("Mobile station international subscriber directory number (MSISDN)", telInf.sim1_MSISDN));
telInf.scitemsArr.add(new Sci("Location Area Code (LAC)", telInf.sim1_LAC));
telInf.scitemsArr.add(new Sci("Cell Tower ID (CID)", telInf.sim1_CellID));
if (telInf.isSIM2Ready) {
telInf.scitemsArr.add(new Sci(" ", " "));
telInf.scitemsArr.add(new Sci("SIM 2 state", telInf.sim2_STATE));
telInf.scitemsArr.add(new Sci("Integrated circuit card identifier (ICCID)", telInf.sim2_ICCID));
telInf.scitemsArr.add(new Sci("Unique device ID (IMEI or MEID/ESN for CDMA)", telInf.sim2_IMEI));
telInf.scitemsArr.add(new Sci("International mobile subscriber identity (IMSI)", telInf.sim2_IMSI));
telInf.scitemsArr.add(new Sci("Service provider name (SPN)", telInf.sim2_SPN));
telInf.scitemsArr.add(new Sci("Mobile country code (MCC)", telInf.sim2_MCC));
telInf.scitemsArr.add(new Sci("Mobile operator name", telInf.sim2_MNC));
telInf.scitemsArr.add(new Sci("Mobile country code + mobile network code (MCC+MNC)", telInf.sim2_MCC_MNC));
telInf.scitemsArr.add(new Sci("Mobile station international subscriber directory number (MSISDN)", telInf.sim2_MSISDN));
telInf.scitemsArr.add(new Sci("Location Area Code (LAC)", telInf.sim2_LAC));
telInf.scitemsArr.add(new Sci("Cell Tower ID (CID)", telInf.sim2_CellID));
//telInf.scitemsArr.add(new Sci("NC (Neighboring Cell ", telInf.sim1_NC.toString() ));
}
return telInf;
}
private static String simState(int simState) {
switch (simState) {
case 0:
return "UNKNOWN";
case 1:
return "ABSENT";
case 2:
return "REQUIRED";
case 3:
return "PUK_REQUIRED";
case 4:
return "NETWORK_LOCKED";
case 5:
return "READY";
case 6:
return "NOT_READY";
case 7:
return "PERM_DISABLED";
case 8:
return "CARD_IO_ERROR";
}
return "??? " + simState;
}
private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws ITgerMethodNotFoundException {
String imsi = null;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimID.invoke(telephony, obParameter);
if (ob_phone != null) {
imsi = ob_phone.toString();
}
} catch (Exception e) {
e.printStackTrace();
throw new ITgerMethodNotFoundException(predictedMethodName);
}
return imsi;
}
private static GsmCellLocation getCellLocBySlot(Context context, String predictedMethodName, int slotID) throws ITgerMethodNotFoundException {
GsmCellLocation cloc = null;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimID = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimID.invoke(telephony, obParameter);
if (ob_phone != null) {
cloc = (GsmCellLocation) ob_phone;
}
} catch (Exception e) {
e.printStackTrace();
throw new ITgerMethodNotFoundException(predictedMethodName);
}
return cloc;
}
private static boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws ITgerMethodNotFoundException {
boolean isReady = false;
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
Class<?>[] parameter = new Class[1];
parameter[0] = int.class;
Method getSimState = telephonyClass.getMethod(predictedMethodName, parameter);
Object[] obParameter = new Object[1];
obParameter[0] = slotID;
Object ob_phone = getSimState.invoke(telephony, obParameter);
if (ob_phone != null) {
int simState = Integer.parseInt(ob_phone.toString());
telInf.sim2_STATE = simState(simState);
if ((simState != TelephonyManager.SIM_STATE_ABSENT) && (simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
isReady = true;
}
}
} catch (Exception e) {
e.printStackTrace();
throw new ITgerMethodNotFoundException(predictedMethodName);
}
return isReady;
}
public static void printTelephonyManagerMethodNamesForThisDevice(Context context) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> telephonyClass;
try {
System.out.println("-------------------------------");
telephonyClass = Class.forName(telephony.getClass().getName());
Method[] methods = telephonyClass.getMethods();
for (Method method : methods) {
// if (methods[idx].getName().startsWith("get")) {
System.out.println("\n" + method.getName() + " declared by " + method.getDeclaringClass());//+ " superclass " + methods[idx].getDeclaringClass().getSuperclass().getName());
//}
}
System.out.println("-------------------------------");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public boolean isSIM1Ready() {
return isSIM1Ready;
}
public boolean isSIM2Ready() {
return isSIM2Ready;
}
private boolean isDualSIM() {
return imsiSIM2 != null;
}
@Override
public String toString() {
return "XXXXXXXXXXXXXXXX TelInfo{" +
"imsiSIM1='" + sim1_IMSI + '\'' +
", imsiSIM2='" + imsiSIM2 + '\'' +
", isSIM1Ready=" + isSIM1Ready +
", isSIM2Ready=" + isSIM2Ready +
'}';
}
private static class ITgerMethodNotFoundException extends Exception {
private static final long serialVersionUID = -996812356902545308L;
public ITgerMethodNotFoundException(String info) {
super(info);
}
}
}
希望对您有所帮助。
关于android - 如果双 Sim 插槽之一中的 Sim 卡发生变化,我如何检索 Sim 卡的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43222959/
我想获取双 SIM 卡手机中两张 SIM 卡的 SIM 卡序列号/ID。有没有办法获取它们?提前致谢。 最佳答案 import java.lang.reflect.Method; im
我知道我们可以使用 TelephonyManager 类检索单个 Sim 卡的信息。但是如何检索有关多张 SIM 卡的信息?比如说,我的手机丢了,有人更换了其中一个插槽中的 SIM 卡。我如何收到包括
我想使用 Python 中的 R 包 fracdiff 和 arfima。我使用 rpy2 作为 导入了这个库 from rpy2.robjects.packages import importr f
这个问题在这里已经有了答案: How to get sim id from iphone (1 个回答) Programmatically get own phone number in iOS
我正在构建一个网络监视器应用程序。在这里,我已成功实现了所有功能,例如跟踪 Wifi 或移动数据的数据使用情况,但我想知道哪个 SIM 卡连接到互联网并使用移动数据。 使用下面的代码,我可以知道我的双
我有一个检测来电的 Android 应用程序,我需要改进这个应用程序以在 duos 移动设备上运行。所以我创建了一个在 list 中注册的广播接收器以进行操作:电话状态已更改,并且在我的 onRece
过去几天我一直在寻找这个,我才知道: “Android开箱即用不支持双卡,是厂商自定义修改,没有公共(public)API控制。” 以下链接中提供了一个解决方案,但它不适用于我的手机三星 Galaxy
我被搜索了有关 NFC SIM 卡的信息,发现 such explanations关于他们在这里和那里: For those who want to use near field communicat
我有一部带 2 张 SIM 卡的 Android 手机,我想检测来电的目标——是 SIM 1 还是 SIM 2。是否可以从通话信息中获取目标号码? 最佳答案 最后我使用这段代码得到了解决方案。希望它对
我有一部带 2 张 SIM 卡的 Android 手机,我想检测来电的目标——是 SIM 1 还是 SIM 2。是否可以从通话信息中获取目标号码? 最佳答案 最后我使用这段代码得到了解决方案。希望它对
我想检查哪个 SIM 卡正在为双卡 android 手机拨出电话。阅读本文 Android : Check whether the phone is dual SIM . 工作起来很有魅力,可以检测
我想在双卡设备中获取两个 sim 号码。 最佳答案 使用 API > 21 需要权限android.Manifest.permission.READ_PHONE_STATE. public class
我尝试为单个 SIM 设备配置 EAP-SIM 并成功连接。现在我想在双 SIM 设备上配置特定的 SIM 卡。 我的观察是在单个 SIM 设备中配置 EAP 时,没有规定指定 SIM 身份。那么如何
如何在具有双 SIM 卡的 Android 中发送短信用于广播而不是 Intent ?如何在android中检测双卡?用户想要选择 sim 卡来发送短信广播。在 android 中设置用于在 andr
我正在开发一个应用程序,我需要知道来电是来自 sim 1 还是 sim 2。在某些设备中,广播接收器会检测到它,但并非所有设备都发生这种检测。 如何检测到 sim 1 或 sim 2 有来电? 最佳答
I searched and read all the questions and answers similar to this question but non is solving my pro
有没有办法以编程方式检查 Android 中的 sim 1 或 sim 2 的移动数据是否处于 Activity 状态? 我还想获得数据处于 Activity 状态的运营商提供商。 情商:sim 1
我想在收到短信时获得 SIM 卡的唯一 ID(line1number 或 simserialnumber...)。它适用于单 SIM 卡。是否可以使用多 SIM 卡? 最佳答案 多 SIM 卡支持仅添
我正在尝试检查我的移动设备是否是双 sim 卡,sim1 是否准备就绪,sim2 是否准备就绪,我已使用 java 反射完成此操作,现在我想知道 sim1 是否正在漫游以及 sim2 是否正在漫游,如
我有双卡 Android 智能手机。我知道 android SDK 不支持双卡双待设备。我想在默认插槽上访问 sim 的 sim 运营商名称。但是当我运行程序时,它给了我一个空字符串。以下是我的代码:
我是一名优秀的程序员,十分优秀!