Get IMSI from the SIM using codename1
Asked Answered
N

2

1

I need to get the IMSI (International Mobile Subsriber Identity) stored in the SIM card using codename1. Also in the case of dual or tri SIM phones, i need to get the IMSI for each SIM. Please, How do i get it?

Norfolk answered 20/7, 2014 at 8:50 Comment(0)
M
0

Display.getMsisdn() will work for some devices but most don't allow accessing that information. For more information you can just use a native interface if you can access it that way.

Moldavia answered 20/7, 2014 at 13:36 Comment(0)
T
0

Another way to get IMSI for dual Sim device:

Try this .. its working for me. Idea is to call service for iphonesubinfo function#3. you will get output as parcel value thats why I use getNumberFromParcel to extract number.

import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Apipas on 6/4/15.
 */
public class SimUtil {

    public static String getIMSI_1() {
        String imsiParcel = runCommand("service call iphonesubinfo 3");
        String imsi = getNumberFromParcel(imsiParcel);
        Log.d("apipas", "IMSI_1:" + imsi);
        return imsi;
    }

    public static String getIMSI_2() {
        String imsiParcel = runCommand("service call iphonesubinfo2 3");
        String imsi = getNumberFromParcel(imsiParcel);
        Log.d("apipas", "IMSI_2:" + imsi);
        return imsi;
    }


    public static String runCommand(String src) {
        try {
            Process process = Runtime.getRuntime().exec(src);
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            int read;
            char[] buffer = new char[2048];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
            }
            reader.close();

            // Waits for the command to finish.
            process.waitFor();

            return output.toString();
        } catch (IOException e) {
            Log.e("apipas", "IOException:" + e.getMessage());
            return null;

        } catch (InterruptedException e) {
            Log.e("apipas", "InterruptedException:" + e.getMessage());
            return null;
        }
    }


    public static String getNumberFromParcel(String str) {
        String res = "";
        if (str != null && str.length() > 0) {
            String lines[] = str.split("\n");
            for (String line : lines) {
                if (line == null || line.length() == 0)
                    continue;
                String content[] = line.split("'");
                if (content.length > 1) {
                    res += content[1].replace(".", "");
                }
            }
        } else return "NA";
        return res;
    }

}

Then call these static methods like:

String imsi1 = SimUtil.getIMSI_1();
String imsi2 = SimUtil.getIMSI_2();

You'd need to set this permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Turmeric answered 4/6, 2015 at 15:23 Comment(1)
Try to run: service call iphonesubinfo2 3 in shell directly and tell me what output you get ?Turmeric

© 2022 - 2024 — McMap. All rights reserved.