以编程方式检索android中双SIM卡的IMEI号

时间:2014-03-20 05:46:15

标签: android imei dual-sim

对于单个SIM代码,以下代码有效:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String imei= tm.getDeviceId();

对于双SIM卡,我尝试了以下链接上的代码:

Android : Check whether the phone is dual SIM

但它对我没有用。

如果有任何其他解决方案,请告诉我。

12 个答案:

答案 0 :(得分:5)

尝试使用API​​级别23中添加的getDeviceId(int slotId)

  

返回订阅的唯一设备ID,例如IMEI   用于GSM和CDMA手机的MEID。如果设备ID不是,则返回null   可用。

     

需要许可:READ_PHONE_STATE

答案 1 :(得分:3)

我们可以通过每个SIM卡使用Android API和IMEI来检查手机是单卡还是双卡双手

TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Log.i("OmSai ", "Single or Dula Sim "+manager.getPhoneCount());
Log.i("OmSai ", "Defualt device ID "+manager.getDeviceId());
Log.i("OmSai ", "Single 1 "+manager.getDeviceId(0));
Log.i("OmSai ", "Single 2 "+manager.getDeviceId(1));

答案 2 :(得分:1)

TelephonyManager telephony = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    try {

        Class<?> telephonyClass = Class.forName(telephony.getClass().getName());
        Class<?>[] parameter = new Class[1];
        parameter[0] = int.class;
        Method getFirstMethod = telephonyClass.getMethod("getDeviceId", parameter);
        Log.d("SimData", getFirstMethod.toString());
        Object[] obParameter = new Object[1];
        obParameter[0] = 0;
        TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String first = (String) getFirstMethod.invoke(telephony, obParameter);
        Log.d("SimData", "first :" + first);
        obParameter[0] = 1;
        String second = (String) getFirstMethod.invoke(telephony, obParameter);
        Log.d("SimData", "Second :" + second);

    } catch (Exception e) {
        e.printStackTrace();
    }

尝试使用此功能,这应该有助于在android lollipop上获取两个设备ID

答案 3 :(得分:1)

是的,我们可以获得两个IMEI号码使用以下代码

<Page
    x:Class="Sample.BlankPage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <WebView
            Source="http://news.google.com"
        />

        <Rectangle
            Fill="Red"
            Opacity="0.25"
            IsHitTestVisible="False"
            MaxWidth="200"
        />

    </Grid>
</Page>

答案 4 :(得分:1)

TelephonyManager first = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG, "Device Id: " + first.getDeviceId() + ", device status: " + first.getSimState() + ", operator: " + first.getNetworkOperator() + "/" + first.getNetworkOperatorName());

obParameter[0] = 1;
TelephonyManager second = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

Log.d(TAG, "Device Id: " + second.getDeviceId() + ", device status: " + second.getSimState()+ ", operator: " + second.getNetworkOperator() + "/" + second.getNetworkOperatorName());

答案 5 :(得分:0)

AFAIK是不可能的。您使用的java反射可以用于某些设备,但不是全部。但是,可能会有一些制造商特定的API允许这样做。

引用Commonsware

  

Android不支持多个SIM,至少来自SDK。设备   已经创建了多SIM卡设备的制造商正在这样做   拥有。欢迎您与设备制造商联系,看看是否   他们有一个SDK插件或允许您访问的插件   第二个SIM。

答案 6 :(得分:0)

是Android目前不支持Dual Sim。但是您可以使用Java反射来检索所有可能的细节。

我研究获取双SIM卡的详细信息,它适用于波纹设备
三星Galaxy Neo
Moto E.
Micromax A52
Micromax帆布
Linovo P780
HTC Dreem
Moto G. LG

华为Y520-U22
LG-​​P705
索尼ST26i
我从上面的模型中成功获得了双SIM卡Detials

答案 7 :(得分:0)

您可以使用此方法获取两个imei。对造成的不便表示歉意。我赶时间。

public static void samsungTwoSims(Context context) {
    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 getFirstMethod = telephonyClass.getMethod("getDefault", parameter);

        Log.d(TAG, getFirstMethod.toString());

        Object[] obParameter = new Object[1];
        obParameter[0] = 0;
        TelephonyManager first = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

        Log.d(TAG, "Device Id: " + first.getDeviceId() + ", device status: " + first.getSimState() + ", operator: " + first.getNetworkOperator() + "/" + first.getNetworkOperatorName());

        obParameter[0] = 1;
        TelephonyManager second = (TelephonyManager) getFirstMethod.invoke(null, obParameter);

        Log.d(TAG, "Device Id: " + second.getDeviceId() + ", device status: " + second.getSimState()+ ", operator: " + second.getNetworkOperator() + "/" + second.getNetworkOperatorName());
    } catch (Exception e) {
        e.printStackTrace();
    }   
}

答案 8 :(得分:0)

您可以在Android O或更高版本中执行IMEI。

Set<String> deviceIdList = new HashSet<>();
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int phoneCount = telephonyManager.getPhoneCount();
for (int i = 0; i < phoneCount; i++) {
   deviceIdList.add(telephonyManager.getImei(i));
}

答案 9 :(得分:0)

步骤: 1>您必须启用READ_PHONE_STATE权限

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

2>对于Android SDK v23 <=通过以下方式获取SIM 1和SIM 2 IMEI:

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    Log.e("IMEI---1:", tm.getDeviceId(0) );
    Log.e("IMEI---2:", tm.getDeviceId(1) );

答案 10 :(得分:0)

尝试以下代码以获取Android设备的IMEI编号:

telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);

    btn_imei.setOnClickListener(new View.OnClickListener() {
        @RequiresApi(api = Build.VERSION_CODES.O)
        @Override
        public void onClick(View v) {
            if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) 
            {
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CODE);
                return;
            }

            StringBuilder stringBuilder = new StringBuilder();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                for (int i = 0; i < telephonyManager.getPhoneCount(); i++) {
                    stringBuilder.append(telephonyManager.getImei(i));
                    stringBuilder.append("\n");
                }
            }
            txt_imei.setText(stringBuilder.toString());
        }
    });

答案 11 :(得分:0)

TelephonyInfo telephonyInfo = TelephonyInfo.getInstance(this);

    String imeiSIM1 = telephonyInfo.getImsiSIM1();
    String imeiSIM2 = telephonyInfo.getImsiSIM2();

    boolean isSIM1Ready = telephonyInfo.isSIM1Ready();
    boolean isSIM2Ready = telephonyInfo.isSIM2Ready();

    boolean isDualSIM = telephonyInfo.isDualSIM();

    TextView tv = (TextView) findViewById(R.id.txt_imei);
    tv.setText(" IME1 : " + imeiSIM1 + "\n" +
            " IME2 : " + imeiSIM2 + "\n" +
            " IS DUAL SIM : " + isDualSIM + "\n" +
            " IS SIM1 READY : " + isSIM1Ready + "\n" +
            " IS SIM2 READY : " + isSIM2Ready + "\n");

}