I am developing application which calculates data and voice usage from user's android phone.
Issue I am facing is differentiating this data according to numbers in dual sim phones.
(e.g. If I make call from SIM 1 then voice usage should be mapped against corresponding number)
I have searched in SO for this kind of code snippet but had no luck.
Is this possible in Android programmatically by any means ?
If yes, then what could be best possible solution for this.
There is no support for dual slim as for today. Thats mean - there is no any official public API available.
Issue 14799: Dual SIM cards supporting
Related
Thank you for review my question.
Now i have problem to send sms from my mobile. i could not access to send sms from both sim card but only primary sim card to use send sms.
Question: How can i use secondary sim card to send sms?
Question: How to get dual sim card information using TelephonyManager in all android version?
I got only one sim card information.
Thank you.
Multiple SIM API is supported only from Lollipop. The phones, which have more than 1 sim, and run on older Android versions have custom ROMs(firmware), edited by their manufacturers to support multi-sim. All they have different API, which is possibly not accessible for third-party apps like yours (only system apps can use it). So if you want something like that to work on all devices, you will have to get the ROMs of all devices, decompile it, and see how the manufacturers modified it. Than you will have to implement different ways to do that for every phone model.
So in other words - it's impossible.
In android system service ,there are TELEPHONY_SERVICE1 ="phone1" and TELEPHONY_SERVICE="phone" in android framework.
I don't have a source, but, I really believe it is used to retrieve TelephonyManager in Dual-Sim phones for the other card.
Except it being kinda obvious from the name, google also drops a lot of chinese results - coincidentally, Dual Sim phones are very popular in china.
I hope someone can back it up with a credible source or test it on a Dual Sim phone.
Has anyone had experience with programming the selection of the SIM card, when the phone uses a dual SIM adapter?
Thanks,
STeN
Added later:
I have found the MultiSim application on the Android Market, which has in its description written that "...Analog dual-sim-adapter users can switch their sim cards...", so is there some API in the Android SDK, which allows the SIM card switch/selection?
The current Android platform does not have support for multiple SIMs. A device with such support has been customized for this, so you will need to get information from that device's manufacturer for any facilities they have to interact with it.
Since nobody mentioned it yet, Android finally has added official multisim support on Android 5.1.
But unless your app is only targeting that API (which is currently less than 0.5% of the market) you are on your own with the more obscure solutions mentioned in the other answers.
Please refer to this Dual Sim Android article. If you follow this direction, I think you can make it, even if current android api doesn't support dual sim card mobile devices.
For SMS:
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 appears manufacturer-independent); 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.)
I'm trying to write a program that change default SIM card on my dual-sim android, what functions do I need for this?
The Android SDK has no support for manipulating multiple SIM cards. You will need to contact the manufacturer of your device and ask them if they have an SDK add-on or something that enables you to work with multiple SIM cards.
If your phone is based on Mediatek, there is a way to do what you want to. Have no doubt about that.
Dual SIM Switch Widget (I've developed it) is able to control SIM states on most dual SIM devices with Mediatek's boards.
Take a look at this page:
http://labs.mediatek.com/site/global/developer_tools/mediatek_android/api_references/mediatek-sdk3/reference/com/mediatek/telephony/TelephonyManagerEx.gsp
Has anyone had experience with programming the selection of the SIM card, when the phone uses a dual SIM adapter?
Thanks,
STeN
Added later:
I have found the MultiSim application on the Android Market, which has in its description written that "...Analog dual-sim-adapter users can switch their sim cards...", so is there some API in the Android SDK, which allows the SIM card switch/selection?
The current Android platform does not have support for multiple SIMs. A device with such support has been customized for this, so you will need to get information from that device's manufacturer for any facilities they have to interact with it.
Since nobody mentioned it yet, Android finally has added official multisim support on Android 5.1.
But unless your app is only targeting that API (which is currently less than 0.5% of the market) you are on your own with the more obscure solutions mentioned in the other answers.
Please refer to this Dual Sim Android article. If you follow this direction, I think you can make it, even if current android api doesn't support dual sim card mobile devices.
For SMS:
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 appears manufacturer-independent); 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.)