i am developing the application in which user mobile no and international country code should be set automatically on the basis of SIM card provider.
i.e if i install this application in first page country code and my phone no should be filled automatically.i want this result as my output.
i have done this using static code but i want to do dynamically.if user uses this application then country code and mobile no should be selected automatically.
i have searched on net but there is not a exact answer of this question.
I have seen the application in which they are doing this thing so how they are doing?
Thanks
There is also one library which will helpful to you for validate user entered Phone number
as
http://code.google.com/p/libphonenumber/
Here is the code snippet that will help you in getting the phone number:
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = tMgr.getLine1Number();
Don't forget to include READ_PHONE_STATE permission in manifest file.
Related
I am trying to validate the user has the sim card in their android phone's sim slot while using our application
Like GPay, the Phonepay app will throw an error when we removed the sim card from the device
In most cases, I am getting security exceptions and a blank or null string in the latest android versions
TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
String mPhoneNumber = tMgr.getLine1Number();
I think a major part of your problem's solution is available here: link
Check it out.
Hope it solves the issue.
I am working on authentication procedure and the best that I found is this link. This matches to my app needs perfectaly.
But problem that I am facing is that , after doing described steps, I get a phone number picker dialog shown ad hidden and I get reply in onActivityResult callback as a canceld result and with empty data.
I do not know why that dialog closes it self not letting the user to choose the phone number and it returned it self in the OnActivityResult with canceled result code.
Please help me , I am stuck in it and I have no clue to go in that direction with.
I think its the problem of SIM. Some sim card allow this and some not. I will suggest you to do testing on real device. And change your sim card to ensure it must not be the carrier problem.
I have the same issue and then I changed SIM card and that codes start working for me. And that was really amazing to notice that it was not working from all sim cards. I am from India. Hope so it will be helpful for any Asian developer.
I have exactly same issue with this.
On some phone(even if it is brand new phone), phone number dialog is appeared and dismissed quickly.
And then credential id is returning null value.
onActivityResult
val credential: Credential? = data.getParcelableExtra(Credential.EXTRA_KEY)
var phoneNumber = credential?.id
if (phoneNumber == null) {
val tMgr = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
phoneNumber = tMgr.line1Number
}
I try to find a reason but failed. Instead, I use telephonyManager in this exceptional case. This is still not a good solution because user should see abnormal behavior and also should agree with phone permission. I also think this is related with SIM card.
How can I get mobile number automatically soon after user installs my android application. When registered in my application without entering manually. I am using the following code.
TelephonyManager manager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String phoneNumber = manager.getLine1Number();
Make sure you have the permission READ_PHONE_STATE in manifest
also please look here for more information!
In my Android app I'm trying to get the user's phone number. I tried the TelephonyManager solution but here in Europe 90% of the SIM cards have that field blank, so the function returns NULL.
I think I could get the user's phone number searching for sent SMS or by querying the Google account. For the SMS method, I tried to load the content provider sms/sent, but the only address field I can extract is the phone number of the person the user sent the SMS to.
For the Google account I have no idea on what to do.
private String getMyPhoneNumber() {
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
Try this, I'm from Poland, and it works well.
The solution: The package name of the manifest is de.org.limindo.limindo2 but the package of the apk is de.org.limindo2 .....
I have to make an application which shows the contact no of the SIM card that is being used in the cell. For that I need to use TelephonyManager class. Can I get details on its usage?
You can use the TelephonyManager to do this:
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
String number = tm.getLine1Number();
The documentation for getLine1Number() says this method will return null if the number is "unavailable", but it does not say when the number might be unavailable.
You'll need to give your application permission to make this query by adding the following to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
(You shouldn't use TelephonyManager.getDefault() to get the TelephonyManager as that is a private undocumented API call and may change in future.)
Hi Actually this is my same question but I didn't get anything.Now I got mobile number and his email-Id from particular Android real device(Android Mobile).Now a days 90% people using what's App application on Android Mobile.And now I am getting Mobile no and email-ID Through this What's app API.Its very simple to use see this below code.
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account ac : accounts)
{
acname = ac.name;
if (acname.startsWith("91")) {
mobile_no = acname;
}else if(acname.endsWith("#gmail.com")||acname.endsWith("#yahoo.com")||acname.endsWith("#hotmail.com")){
email = acname;
}
// Take your time to look at all available accounts
Log.i("Accounts : ", "Accounts : " + acname);
}
and import this API
import android.accounts.Account;
import android.accounts.AccountManager;
I have to make an application which shows the Contact no of the SIM card that is being used in the cell. For that I need to use Telephony Manager class. Can i get details on its usage?
Yes,
You have to use Telephony Manager;If at all you not found the contact no. of user;
You can get Sim Serial Number of Sim Card and Imei No. of Android Device by using the same Telephony Manager Class...
Add permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Import:
import android.telephony.TelephonyManager;
Use the below code:
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
imei = tm.getDeviceId();
// get SimSerialNumber
simSerialNumber = tm.getSimSerialNumber();
Well, all could be temporary hacks, but there is no way to get mobile number of a user. It is against ethical policy.
For eg, one of the answers above suggests getting all accounts and extracting from there. And it doesn't work anymore!
All of these are hacks only.
Only way to get user's mobile number is going through operator. If you have a tie-up with mobile operators like Aitel, Vodafone, etc, you can get user's mobile number in header of request from mobile handset when connected via mobile network internet.
Not sure if any manufacturer tie ups to get specific permissions can help - not explored this area, but nothing documented atleast.
Sometimes you can retreive the phonenumber with a USSD request to your operator.
For example I can get my phonenumber by dialing *116#
This can probably be done within an app, I guess, if the USSD responce somehow could be catched.
Offcourse this is not a method I would recommend to use within an app that is to be distributed, the code may even differ between operators.
As many said:
String phoneNumber = TelephonyManager.getDefault().getLine1Number();
The availability depends strictly on the carrier and the way the number is encoded on the SIM card. If it is hardcoded by the company that makes the SIMs or by the mobile carrier itself. This returns the same as in Settings->about phone.