Dual Sim Android
Asked Answered
T

4

11

Is there a way that I can access the other sim in my android? I have an android Cherry Mobile Orbit which is a dual sim android phone. I want to develop an SMS application for my phone, but only the 1st sim will be access. I want to access the other sim, so that when i press enter to send the message, there will be a prompt, that which sim the message will be sent. I know that it's propreitary, but the phone manufacturer has no feedback about it. Is there any other way? tweaking or something?

Tiepolo answered 5/11, 2011 at 6:25 Comment(3)
take a look on my code by which I am capable to manage which SIM to use for sending SMS:https://mcmap.net/q/89391/-how-to-send-a-sms-using-smsmanager-in-dual-sim-mobile .. I hope that'd helpHydrosol
Here is a complete solution for android 5 and older #27352436Hydrosol
For the folks looking for a solution that works for API level 22+, please refer to https://mcmap.net/q/89392/-option-to-send-sms-using-sim1-or-sim2-programmaticallyIndoaryan
M
3

I think you can use dex2jar or apktool to reverse those app which runs on dual sim card devices, once you found the related "service manager", "telephony manager",some interface stub, or some key words like "Gemini" you can then use Java Reflection, reflects all of method of this class. Then you can achieve this goal.

Mummery answered 24/11, 2013 at 6:28 Comment(3)
could you please give more details? @MummerySejant
@Sejant after you decompile those apps with dex2jar, try find some class named TelephonyMgr.java, you should find something interesting after you compare the android source code~Mummery
Look into this: #14517838Pacer
M
1

This method can be used to select one SIM from 2 SIMs!

//above Android API 22
if (Build.VERSION.SDK_INT > 22) {
    //for dual sim mobile
    SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);

    if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
     //if there are two sims in dual sim mobile
        List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
        SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
        SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);

        final String sim1 = simInfo.getDisplayName().toString();
        final String sim2 = simInfo1.getDisplayName().toString();

    }else{
     //if there is 1 sim in dual sim mobile
        TelephonyManager tManager = (TelephonyManager) getBaseContext()
                .getSystemService(Context.TELEPHONY_SERVICE);

        String sim1 = tManager.getNetworkOperatorName();

    }

}else{
    //below android API 22
            TelephonyManager tManager = (TelephonyManager) getBaseContext()
                    .getSystemService(Context.TELEPHONY_SERVICE);

            String sim1 = tManager.getNetworkOperatorName();
}

Then to send an SMS you can use the below method

    public static boolean sendSMS(Context context, String smsText) {
    SmsManager smsMan = SmsManager.getDefault();

    SharedPreferences prefs = context.getSharedPreferences("uinfo", MODE_PRIVATE);
    String sim = prefs.getString("sim", "No name defined");
    String simName = prefs.getString("simName", "No name defined");
    String toNum = "";

    try {

        if (Build.VERSION.SDK_INT > 22) {

            SubscriptionManager localSubscriptionManager = SubscriptionManager.from(context);
            if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {

                int simID  = Integer.parseInt(sim);

                List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
                SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(simID);
                ArrayList<String> parts = smsMan.divideMessage(smsText);
                SmsManager.getSmsManagerForSubscriptionId(simInfo.getSubscriptionId()).sendMultipartTextMessage(toNum, null, parts, null, null);
            }else{
                ArrayList<String> parts = smsMan.divideMessage(smsText);
                smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
            }
            return true;
        }else{
            ArrayList<String> parts = smsMan.divideMessage(smsText);
            smsMan.sendMultipartTextMessage(toNum, null, parts, null, null);
        }
    } catch (Exception e) {

    }
    return false;
}
Miscount answered 26/11, 2020 at 21:25 Comment(0)
B
0

Officially right now there is no API to support this, you have to contact the device manufacturer.

Boyes answered 5/11, 2011 at 7:46 Comment(1)
thank you for the feedback @Reno. im still hoping if theres any tweak to it.Tiepolo
G
0

Assuming that you are developing the app for your own phone, and you are willing to go through the trouble of finding out the IDs (sim_id) assigned to each of your SIM cards (probably via checking the phone's log outputs, searching for sim_id, which was what I did), you can use the following code to set the default SIM for SMS sending:

int simId = <place desired SIM ID here>;
Intent simIntent = new Intent("android.intent.action.SMS_DEFAULT_SIM");
simIntent.putExtra("simid", simId);
sendBroadcast(simIntent);

Combined with some other UI prompt stuff (for actually 'picking' the preferred SIM), this should do the trick.

I'm not at all sure if this approach would work for you (although the code seems quite 'standard'); I figured it out with trial and error on my Mlais MX28 (with a customized ROM). But it's still worth a shot, I suppose. :)

UPDATE: Strangely, the solution stopped working unexpectedly after a few updates to the app I was working on. But I came across another way (which seems to be more promising). (I believe this can be extended for other SIM selection scenarios as well, as the settings cache contains entries with names gprs_connection_sim_setting, voice_call_sim_setting, video_call_sim_setting and the like.)

ContentValues val = new ContentValues();
val.put("value", "here goes the preferred SIM ID");
getContentResolver().update(Uri.parse("content://settings/system"), val, "name='sms_sim_setting'", null);

(Unfortunately, this requires the android.permission.WRITE_SETTINGS permission.)

Galvanism answered 13/4, 2015 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.