web-dev-qa-db-ja.com

Android:電話がデュアルSIMかどうかを確認します

フォーラムで多くの調査を行った結果、デュアルSIM電話の両方のSIMカードのIMSIまたはSIMシリアル番号を見つける方法がないことがわかりました(製造元への連絡を除く)。さて、私の変更された質問は、電話に2つのSIMがあることをまったく検出できますか?何らかの知性で検出できると思います。私が考えることができるいくつかの方法は次のとおりです。

  1. USSDコードをダイヤルし、IMEI番号のログをトレースします(インドで* 139#でこれを試しました。動作しました)。これにより、USSDコードをダイヤルしたSIMのIMEI番号がわかります。 (電話機はAndroidガイドラインに従い、2つのIMEI番号を持っていると想定されます。)

  2. SIMのSIMシリアル番号やIMSIを保存します。また、一部のログをトレースしたり、ブロードキャストイベントを処理したりして、電話が再起動されなかった(つまりSIMが切り替えられた)場合でも、他のIMSI /シリアル番号を検出した後。

  3. * 06#をダイヤルすると、両方のIMEI番号が表示されます。何らかの方法で、これらの2つの数値を取得します。 (テキストのスクリーンキャプチャや画像解析のようなもの。)

誰か他の方法を考えることができるなら、彼らは大歓迎です。私はこれに関してどんな種類の助けも本当に感謝します。また、製造元のAPIまたはそれらに連絡するためのリンクに関する情報がある場合は、コミュニティの人々と共有してください。

111
Rajkiran

15年3月23日更新:

公式の複数のSIM APIはAndroid 5.1以降から利用可能になりました

その他の可能なオプション:

Javaリフレクションを使用して、両方のIMEI番号を取得できます。

これらのIMEI番号を使用して、電話がデュアルSIMかどうかを確認できます。

次のアクティビティを試してください:

import Android.app.Activity;
import Android.os.Bundle;
import Android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        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.tv);
        tv.setText(" IME1 : " + imeiSIM1 + "\n" +
                " IME2 : " + imeiSIM2 + "\n" +
                " IS DUAL SIM : " + isDualSIM + "\n" +
                " IS SIM1 READY : " + isSIM1Ready + "\n" +
                " IS SIM2 READY : " + isSIM2Ready + "\n");
    }
}

そして、これはTelephonyInfo.Javaです:

import Java.lang.reflect.Method;

import Android.content.Context;
import Android.telephony.TelephonyManager;

public final class TelephonyInfo {

    private static TelephonyInfo telephonyInfo;
    private String imeiSIM1;
    private String imeiSIM2;
    private boolean isSIM1Ready;
    private boolean isSIM2Ready;

    public String getImsiSIM1() {
        return imeiSIM1;
    }

    /*public static void setImsiSIM1(String imeiSIM1) {
        TelephonyInfo.imeiSIM1 = imeiSIM1;
    }*/

    public String getImsiSIM2() {
        return imeiSIM2;
    }

    /*public static void setImsiSIM2(String imeiSIM2) {
        TelephonyInfo.imeiSIM2 = imeiSIM2;
    }*/

    public boolean isSIM1Ready() {
        return isSIM1Ready;
    }

    /*public static void setSIM1Ready(boolean isSIM1Ready) {
        TelephonyInfo.isSIM1Ready = isSIM1Ready;
    }*/

    public boolean isSIM2Ready() {
        return isSIM2Ready;
    }

    /*public static void setSIM2Ready(boolean isSIM2Ready) {
        TelephonyInfo.isSIM2Ready = isSIM2Ready;
    }*/

    public boolean isDualSIM() {
        return imeiSIM2 != null;
    }

    private TelephonyInfo() {
    }

    public static TelephonyInfo getInstance(Context context){

        if(telephonyInfo == null) {

            telephonyInfo = new TelephonyInfo();

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

            telephonyInfo.imeiSIM1 = telephonyManager.getDeviceId();;
            telephonyInfo.imeiSIM2 = null;

            try {
                telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdGemini", 0);
                telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdGemini", 1);
            } catch (GeminiMethodNotFoundException e) {
                e.printStackTrace();

                try {
                    telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceId", 0);
                    telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceId", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();
                }
            }

            telephonyInfo.isSIM1Ready = telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
            telephonyInfo.isSIM2Ready = false;

            try {
                telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimStateGemini", 0);
                telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimStateGemini", 1);
            } catch (GeminiMethodNotFoundException e) {

                e.printStackTrace();

                try {
                    telephonyInfo.isSIM1Ready = getSIMStateBySlot(context, "getSimState", 0);
                    telephonyInfo.isSIM2Ready = getSIMStateBySlot(context, "getSimState", 1);
                } catch (GeminiMethodNotFoundException e1) {
                    //Call here for next manufacturer's predicted method name if you wish
                    e1.printStackTrace();
                }
            }
        }

        return telephonyInfo;
    }

    private static String getDeviceIdBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

        String imei = 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){
                imei = ob_phone.toString();

            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeminiMethodNotFoundException(predictedMethodName);
        }

        return imei;
    }

    private static  boolean getSIMStateBySlot(Context context, String predictedMethodName, int slotID) throws GeminiMethodNotFoundException {

        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 getSimStateGemini = telephonyClass.getMethod(predictedMethodName, parameter);

            Object[] obParameter = new Object[1];
            obParameter[0] = slotID;
            Object ob_phone = getSimStateGemini.invoke(telephony, obParameter);

            if(ob_phone != null){
                int simState = Integer.parseInt(ob_phone.toString());
                if(simState == TelephonyManager.SIM_STATE_READY){
                    isReady = true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeminiMethodNotFoundException(predictedMethodName);
        }

        return isReady;
    }


    private static class GeminiMethodNotFoundException extends Exception {

        private static final long serialVersionUID = -996812356902545308L;

        public GeminiMethodNotFoundException(String info) {
            super(info);
        }
    }
}

編集:

他のSIMスロットの詳細について「getDeviceIdGemini」などのメソッドへのアクセスを取得すると、メソッドが存在することが予測されます。

そのメソッドの名前がデバイスの製造元から指定された名前と一致しない場合、機能しません。これらのデバイスに対応するメソッド名を見つける必要があります。

他のメーカーのメソッド名を見つけるには、次のようにJavaリフレクションを使用します。

public static void printTelephonyManagerMethodNamesForThisDevice(Context context) {

    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    Class<?> telephonyClass;
    try {
        telephonyClass = Class.forName(telephony.getClass().getName());
        Method[] methods = telephonyClass.getMethods();
        for (int idx = 0; idx < methods.length; idx++) {

            System.out.println("\n" + methods[idx] + " declared by " + methods[idx].getDeclaringClass());
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
} 

EDIT:

Seetha が彼女のコメントで指摘したように:

telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getDeviceIdDs", 0);
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getDeviceIdDs", 1); 

彼女のために働いています。彼女は、Samsung Duosデバイスの両方のSIMに対して2つのIMEI番号を取得することに成功しました。

<uses-permission Android:name="Android.permission.READ_PHONE_STATE" />を追加

EDIT 2:

データの取得に使用される方法は、Lenovo A319およびその製造元の他の携帯電話向けです(クレジット Maher Abuthraa ):

telephonyInfo.imeiSIM1 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 0); 
telephonyInfo.imeiSIM2 = getDeviceIdBySlot(context, "getSimSerialNumberGemini", 1); 
180
Vaibhav Jani

Android 4.4.4を備えたSamsung Duosデバイスがあり、Seethaが承認済みの回答(getDeviceIdDsの呼び出し)で提案したメソッドは、メソッドが存在しないため機能しません。以下に示すように、メソッド "getDefault(int slotID)"を呼び出すことで、必要なすべての情報を回復できました。

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

また、一連のtry/catchではなくメソッド名の配列を使用するように、この情報を回復するメソッドを繰り返しテストするコードを書き直しました。たとえば、2つのアクティブなSIMがあるかどうかを判断するには、次のようにします。

private static String[] simStatusMethodNames = {"getSimStateGemini", "getSimState"};


public static boolean hasTwoActiveSims(Context context) {
    boolean first = false, second = false;

    for (String methodName: simStatusMethodNames) {
        // try with sim 0 first
        try {
            first = getSIMStateBySlot(context, methodName, 0);
            // no exception thrown, means method exists
            second = getSIMStateBySlot(context, methodName, 1);
           return first && second;
        } catch (GeminiMethodNotFoundException e) {
            // method does not exist, nothing to do but test the next
        }
    }
    return false;
}

このようにして、あるデバイスに新しいメソッド名が提案された場合、それを配列に追加するだけで機能します。

ネットワークオペレーターを確認する方法を検索しているときに見つけたネイティブソリューションがいくつかあります。

API> = 17の場合:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

// Get information about all radio modules on device board
// and check what you need by calling #getCellIdentity.

final List<CellInfo> allCellInfo = manager.getAllCellInfo();
for (CellInfo cellInfo : allCellInfo) {
    if (cellInfo instanceof CellInfoGsm) {
        CellIdentityGsm cellIdentity = ((CellInfoGsm) cellInfo).getCellIdentity();
        //TODO Use cellIdentity to check MCC/MNC code, for instance.
    } else if (cellInfo instanceof CellInfoWcdma) {
        CellIdentityWcdma cellIdentity = ((CellInfoWcdma) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoLte) {
        CellIdentityLte cellIdentity = ((CellInfoLte) cellInfo).getCellIdentity();
    } else if (cellInfo instanceof CellInfoCdma) {
        CellIdentityCdma cellIdentity = ((CellInfoCdma) cellInfo).getCellIdentity();
    } 
}

AndroidManifestで許可を追加します。

<manifest xmlns:Android="http://schemas.Android.com/apk/res/Android"
    <uses-permission Android:name="Android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

ネットワークオペレーターを取得するには、mccおよびmncコードを確認できます。

API> = 22の場合:

final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
final List<SubscriptionInfo> activeSubscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
for (SubscriptionInfo subscriptionInfo : activeSubscriptionInfoList) {
    final CharSequence carrierName = subscriptionInfo.getCarrierName();
    final CharSequence displayName = subscriptionInfo.getDisplayName();
    final int mcc = subscriptionInfo.getMcc();
    final int mnc = subscriptionInfo.getMnc();
    final String subscriptionInfoNumber = subscriptionInfo.getNumber();
}

API> = 23の場合。電話がデュアル/トリプル/多くのシムであるかどうかを確認するには:

TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
if (manager.getPhoneCount() == 2) {
    // Dual sim
}
4
oxied

OnePlus 2 Phoneから両方のIMEIを読むことができます

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                TelephonyManager manager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
                Log.i(TAG, "Single or Dual Sim " + manager.getPhoneCount());
                Log.i(TAG, "Default device ID " + manager.getDeviceId());
                Log.i(TAG, "Single 1 " + manager.getDeviceId(0));
                Log.i(TAG, "Single 2 " + manager.getDeviceId(1));
            }
3
Swapnil Godambe

通話ログを見ていたところ、managedCursorのコンテンツの通常のフィールドとは別に、各通話にタグを付けるために、デュアルSIM電話(「Xolo A500s Lite」で確認)に「simid」列があることに気付きました。 SIMを使用した通話ログで。この値は1または2で、おそらくSIM1/SIM2を示しています。

managedCursor = context.getContentResolver().query(contacts, null, null, null, null);
managedCursor.moveToNext();        
for(int i=0;i<managedCursor.getColumnCount();i++)
{//for dual sim phones
    if(managedCursor.getColumnName(i).toLowerCase().equals("simid"))
        indexSIMID=i;
}

単一のSIM電話ではこの列が見つかりませんでした(Xperia Lで確認しました)。

したがって、これはデュアルSIMの性質をチェックする確実な方法ではないと思いますが、誰かに役立つ可能性があるため、ここに掲載しています。

2
zafar142003

ヒント:

使用してみることができます

ctx.getSystemService("phone_msim")

の代わりに

ctx.getSystemService(Context.TELEPHONY_SERVICE)

すでにVaibhavの答えを試したが、telephony.getClass().getMethod()が失敗した場合、上記は私のQualcomm mobileで機能します。

1
Bruce

Samsung S8でこれらのシステムプロパティを見つけました

SystemProperties.getInt("ro.multisim.simslotcount", 1) > 1

また、ソースによると: https://Android.googlesource.com/platform/frameworks/base/+/master/telephony/Java/com/Android/internal/telephony/TelephonyProperties.Java

getprop persist.radio.multisim.configは、マルチSIMで「dsds」または「dsda」を返します。

私はこれをSamsung S8でテストしましたが、動作します

0
kakopappa

Commonswareは、これは不可能だと言います。以下をご覧ください。

Android SDKを使用してデュアルSIMを検出することはできません。

この件に関する詳細なダイアログは次のとおりです。

Google開発チームの担当者は、Android SDKを使用したデュアルSIMの検出は不可能だと言っています。

0
gonzobrains