How to determine the number of SIM cards on a device? - java

Sometimes we encounter some devices which have two or more SIM cards. So my question is:
How can I determine the number of SIM cards on the device?
Actually, I am developing a field test app and for example, if I have 2 SIM cards on the device, the user can choose between them to launch measurements.

There is currently no Android API for handling multiple SIM cards; any device support is entirely down to the handset manufacturer having modified the Android source. You could see if the particular manufacturer offers any kind of SDK or published API to help you, but it will be on a case by case basis.

All phones that support multiple sim card switching do so outside the android SDK so you'd have to contact their manufacturers for information about how they expose this functionality.

The question is very outdated and probably the answer was already found. But this may help someone else.
Beginning from Android API 22 you can do so via the SubscriptionManager like below:
val subManager = getSystemService(TELEPHONY_SUBSCRIPTION_SERVICE) as SubscriptionManager
val simCount = subManager.activeSubscriptionInfoCountMax //Total supported sim cards by device
val simAvailable = subManager.activeSubscriptionInfoCount // Currently active sim cards amount

Related

How to get SKU code, Buyer Code and CSC in Android Studios

I'm developing an Android App and I need to be able to capture the SKU, Buyer Code and CSC of the device (only Samsung smartphones). I guess I only need the Buyer code (Country Code) and the CSC, but I've been searching and it looks like the SKU code already has these two codes.
I need these codes so I can restrict my App to some specific smartphones, specifically those that where bought in a specific country.
I can't find a way or a class that will help me get these information. I'm already capturing the device's IMEI and model, but not the Buyer Code or CSC.
I appreciate if someone can help me with this.
I found that post providing some Basic information.
How to obtain Firmware version of Android programmatically?
Some data like CSC are given by different ways depending on the manufacturer.
For Samsung for example, you will find information about software in /system/SW_Configuration.xml and about buyer in /system/csc/sales_code.dat and /efs/imei/mps_code.dat

Is it possible to Turn Off USB Storage on Android Devices programatically?

I have tried to search over and over and got confused whether we can have control over USB storage without rooting the phone,if yes than how? I have tried the following method to enable and disable the permission but all in vain:
StorageManager storage = (StorageManager)getApplicationContext().getSystemService(STORAGE_SERVICE);
Method method = storage.getClass().getDeclaredMethod("enableUsbMassStorage");
method.setAccessible(true);
Object r = method.invoke(storage);
//And to disble mass storage:
StorageManager storage = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);
Method method = storage.getClass().getDeclaredMethod("disableUsbMassStorage");
method.setAccessible(true);
Object r = method.invoke(storage);
If anyone has any idea about this please do share your knowledge.
Thanks in advance.
The short answer to your question is NO. You cannot play around with the USB mass storage permission programmatically. You also wont find any Android apps that can do this reliably for any/all phones.
By default, the Android framework does not allow third-party applications to programmatically bypass the USB storage permissions. That choice is always left to the user, and that is the correct approach. Just think about it: if it were permitted, any third-party app could misuse that permission and transfer data over the USB connection.
The approach you have tried to use assumes that we know the names of the relevant methods and call them through reflection. This will work for certain OEMs' that have modified the base framework and exposed the relevant API calls. But it assumes that you know the names of those methods, and it will only work on a tiny subset of the vast number of Android phone models out there. It won't work on most phones, and it certainly wont work on any of the Nexus devices that have the original Android OS source code.
That is all.
If currently your Sd card is SHARED it means that it has connected to PC in MSC mode, you can check this case as following:
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_SHARED.equals(state)) {
// Sd card has connected to PC in MSC mode
}
Now You can force to turn off usb mass storage connection by calling:
MountService.setUsbMassStorageEnabled(false);
//or
StorageManager.disableUsbMassStorage();
//but unfortunately, both these API are not public accessible?!

How to get mobile number phone on android 4.1.2 ? [duplicate]

This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 9 years ago.
I want to get mobile number of own mobile, for add this part to my application .
I'm searching about this question ,
code is correct on emulator but in device show empty.
public String getMyPhoneNumber()
{
return ((TelephonyManager) getSystemService(TELEPHONY_SERVICE))
.getLine1Number();
}
and :
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
But is it returning empty value. So How can I fetch the phone number detail ?
The method you are using is the only one part of the SDK to do this, and only works on devices where the number is stored on the SIM card, which only some carriers do. For all other carriers, you will have to ask the user to enter the phone number manually, as the number is simply not stored anywhere on the device from where you can retrieve it.
Answer from: Programmatically obtain the phone number of the Android phone
"There is no guaranteed solution to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone. This is especially true in some countries which requires physical address verification, with number assignment only happening afterwards. Phone number assignment happens on the network - and can be changed without changing the SIM card or device (e.g. this is how porting is supported).
I know it is pain, but most likely the best solution is just to ask the user to enter his/her phone number once and store it."
Your code should be fine, but you need the SIM card to be inserted in the phone. Also, as autocrat noted, if the number is not stored on sim card, you will get an empty string.
EDIT: Also, please check the link provided by Pontus Backlund, there's some good info there.
Go to setting -> about device -> status -> my phone number if my phone number is unknown u won't get mobile number.. because some of the mobile network won't give mobile number..
if my mobile number has number u can get mobile through following code
TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
phoneNumber = tManager.getLine1Number();

Is telephony manager values reliable and changeable (cdma)?

I want to know if I can rely on the telephony values like country, MCC, etc on Android for my app. Can I change them on the run using setprop? I tried changing using setprop it didn't seem to work. From my understanding telephony manager is a class/interface which represents Hardware configuration of GSM or CDMA. In case of GSM this could be sim and in case of CDMA it cud be a hardware. My questions are:
Who update these values in both the cases for the first time?
Are these values are saved by OS as read only?
What if a user travels to different country or zone will some of the values like country code and MCC values updated automatically?
Can I reset these values?
I have no intention of changing any of these values but want to understand its working! I would appreciate if someone can help me on this.
According to android documentation
Provides access to information about the telephony services on the
device. Applications can use the methods in this class to determine
telephony services and states, as well as to access some types of
subscriber information. Applications can also register a listener to
receive notification of telephony state changes.
TelephonyManager is used for reading phone information. Regarding your question about MCC & MNC codes: yes, they will change when phone will be in other country. You can subscribe to receive those events and determine that user now in different country.
#Bo
The way CDMA works is different from GSM. CDMA has always got one home base and many visitor base location. and you can always get to know about visitor Operator using TelephonyManager methods which is considered as unreliable for CDMA.
I decided to add it as answer as well...
I found a way to tackle this problem on CDMA phone.. if it is a CDMA phone , then the phone always has an ICC hardware comparable to SIM cards in GSM. All you gotta do is use the system properties associated with the hard ware . Programmatically you can use Java reflection to get this information . This is not changeable even system is rooted unlike GSM device. Class c=Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); String homeOperator = ((String) get.invoke(c, "ro.cdma.home.operator.numeric"));

Dial using second sim card (j2me)

For dual sim phones, such as samsung D780, is there a way to dial a number using second sim card.
What I currently use is
platformRequest("tel:+1201xxxxxx");
I have tried playing with ;tsp= but with no success.
Did you tried using AT commands for the same , may be ATD 9999999999 would help , look for complete help on AT Commands. AT Commands are simple ATTENTION commands that are issued to SIM either by MODEM/PHONE inorder to make sim perform some actions.

Categories