Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codenameone 使用代码名1从SIM卡获取IMSI_Codenameone - Fatal编程技术网

Codenameone 使用代码名1从SIM卡获取IMSI

Codenameone 使用代码名1从SIM卡获取IMSI,codenameone,Codenameone,我需要得到IMSI(国际) 手机收信人身份)使用代码名1存储在SIM卡中。此外,如果是双卡或三卡手机,我需要获得每个SIM卡的IMSI。请问,我如何获取它?Display.getMsisdn()将适用于某些设备,但大多数设备不允许访问该信息。有关更多信息,如果您可以通过这种方式访问本机接口,则可以使用本机接口。获取双Sim设备IMSI的另一种方法: 试试这个。。这对我有用。这个想法是为iphonesubinfo功能调用服务#3。您将得到作为地块值的输出,这就是为什么我使用getNumberFro

我需要得到IMSI(国际)
手机收信人身份)使用代码名1存储在SIM卡中。此外,如果是双卡或三卡手机,我需要获得每个SIM卡的IMSI。请问,我如何获取它?

Display.getMsisdn()
将适用于某些设备,但大多数设备不允许访问该信息。有关更多信息,如果您可以通过这种方式访问本机接口,则可以使用本机接口。

获取双Sim设备IMSI的另一种方法:

试试这个。。这对我有用。这个想法是为iphonesubinfo功能调用服务#3。您将得到作为地块值的输出,这就是为什么我使用getNumberFromParcel来提取数字

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;
    }

}
然后调用以下静态方法:

String imsi1 = SimUtil.getIMSI_1();
String imsi2 = SimUtil.getIMSI_2();
您需要设置此权限:

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

尝试运行:服务直接在shell中调用iphonesubinfo2 3,并告诉我您得到了什么输出?