How to get user both inserted sim card number? [duplicate] - java

This question already has answers here:
Programmatically obtain the phone number of the Android phone
(22 answers)
Closed 2 years ago.
In my app i want to show the both inserted sim card mobile number to user in android studio . But i suffer from problem in which , i stuck at getting of second inserted sim mobile number . Help me to solve this.

TelephonyManager - "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."
Code:
TelephonyManager telephonyManager =(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
//SIM 1 Number
String mSimPhoneNumber1 = telephonyManager.getLine1Number();
//SIM 2 Number
String mSimPhoneNumber2 = telephonyManager.getLine2Number();
This method might returns a null on some phones.
Required Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Related

How get my phone number on android using CallLog

In my app I'm using CallLog's and I'm getting data of calls. I can receive all data, but there is no information about my number phone. How can I receive this information? getLine1Number() from TelephonyManager return empty string..
To get the phone number from the device , first you have to set your own phone number on the device, just through :
Settings -> About Phone -> Status -> My phone Number
Phone numbers are not available on SIM for each operators, like in india Sim dont have phone numbers in any memory, So WE cant get phone number from these connection. However, some countries, and operators have stored phone numbers on SIM, and we can get those.
Yes. This is because not all operators support retrieving phone number from the SIM card. There is no fail-safe way to always retrieve the phone number through your app. Your best bet is to ask the user to enter their phone number into the app and then save it to shared preferences or something.
It depends on Mobile Operator. In India Airtel support this feature.

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

How to get IMEI for J2ME supported all devices? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
how to dynamically get mobile IMEI number in J2me?
is there any way to get IMEI for J2ME supported all devices??i did some googling and find out the below solution but it is for device specific.
Nokia.
System.getProperty("com.nokia.IMEI");
SonyEricsson
System.getProperty("com.sonyericsson.imei");
Motorola
System.getProperty("com.motorola.IMEI");
is there any generic way to fetch IMEI for all devices??
There is no generic method to fetch IMEI for all devices, you have to do it by coding only. You can try it in alternate way like use System class as follows,
System.getProperty(“microedition.platform”);
This will going to return you the name of the host platform or device. In Nokia devices the name consists of “Nokia”, the device model, and software version separated by “/”. There is no space between “Nokia” and the model number nor on either side of “/”. Formally, the syntax of the platform string is: Nokia MODEL_NUMBER “/” SW_VERSION. For example, Nokia6310i/4.42 or Nokia3510i/p1.25.
From the result you can fetch the manufacture and use Switch case to get IMEI by coding,

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

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

Android capture new outgoing call [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Android: Redirect outgoing calls
The requirement is to replace newly dialed number with another one. I have captured the ACTION_NEW_OUTGOING_CALL event and used Intent.EXTRA_PHONE_NUMBER to get the current outgoing number and then I have used setResultData inside my class(which extends BroadcastReceiver) to replace the dialed number. Basically code is,
if (Intent.ACTION_NEW_OUTGOING_CALL.equals(action)) {
String phonenbr =
intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.d("OutGoingNum", "phonenbr is " + phonenbr);
if (phonenbr.startsWith("00")) {
setResultData("12345678");
}
}
My code works fine in Android emulator but on the device the code works only on Redial. It doesnt work when you dial the number via dialpad. Please help.
I am guessing that Android won't allow the interception and replacement of a dialed number. It would be far too easy for someone to abuse this.

Categories