top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create a dialog box in my app that asks me to select a sim if the device has dual sim?

+2 votes
1,660 views

I am writing a messaging app in android studio. When I hit the send button it should show me the option to select a sim card if the device has dual sim. If not it should not show the dialog box and should select the default by its own. What should be used for this scenario?

posted Nov 17, 2016 by Bhagyashree R

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Official google devices have no this function. 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.

2 Answers

+2 votes
 
Best answer

Hi, as far as I know there is no direct way to trigger an in-built dialog box. So, I would suggest to get the sim information first then create a dialog box on your own. There are more than 1 ways to accomplish this. One method is to use reflection and other way is to read from system db located at /data/data/com.android.providers.telephony/databases/telephony.db. But both of these methods are not so reliable (may not work on all the devices).

However, if you are target is Android 22 and above, then using android SubscriptionManager and SmsManager is reliable.

Get sim(s) information with,

SubscriptionManager subscriptionManager = SubscriptionManager.from(getApplicationContext());
List<SubscriptionInfo> subscriptionInfoList = subscriptionManager.getActiveSubscriptionInfoList();
List<double> subscriptionIds = new ArrayList<double>();
for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
    subscriptionIds.add(subscriptionInfo.getSubscriptionId());
}

// subscriptionIds will have the information about the sims
// Create your own dialog box to handle the selection

Send the sms with,

SmsManager.getSmsManagerForSubscriptionId(int subscriptionId).sendTextMessage(String destinationAddress, String scAddress, String text,PendingIntent sentIntent, PendingIntent deliveryIntent);

Hope this helps!

answer Nov 19, 2016 by Vinod Kumar K V
Thank you
Welcome. :)
+1 vote

All methods to handle multiSIM devices uses subscriptionId. You can get it thru SubscriptionManager.
MultiSIM devices are handled by Android since API level 22 (Android 5.1).

https://developer.android.com/reference/android/telephony/SubscriptionManager.html

answer Dec 2, 2016 by anonymous
Similar Questions
0 votes

Hi,Recently I made an app which takes photo and set to an ImageView in android.In samsung phone its orientation is 90 while camera intent opens so I used ExifInterface with four case 90/180/270/0 with normal case (0 degree) but when I compiled this method,its working perfect in all samsung device which is setting image after reverse rotate 90 to ImageView but not with others like moto/redmi/asus/karbonn I checked on each phone and there is an error that they are not getting bitmap.but when I removed ExifInterface and orientation,it started to work with all devices.but same issue with samsung device that setting image in ImageView with 90 degree orientation.
So I decided to use switch for samsung and other device so how can I know whether app is installed in samsung device or others using java?

+1 vote

Usually Iphones etc are locked with some operator e.g. AT&T etc which then onwards cannot be used with others unless these gets unlocked with s/w upgrade etc.

My question is about making this locking configurable with a SIM[s] and not with an operator. This is to address the phone thefts etc. This way the users can lock the phone with a particular SIM. This locking can be removed later by users themselves. This may also need the operators/phone manufacturers support based on the mechanism. Here any s/w only mechanism may be forcefully overridden upon the wholesale reformat hence some device level support may be needed.

I am not sure if this mechanism already exists.

+1 vote

Is it possible to create a tool to switch sim 1 and sim 2 , on and off separately. If possible with a timer?
I want my sim2 , business calls , shut down when workday is over and on when in start in the morning.

...