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 .....
Related
I've googled this for hours but can't seem to find an answer.
I want to grab the unique device ID upon first login and store it in the users firestore document so that I can identify each device associated with that users account, I'm already using the onCreate firebase cloud function to generate fields upon first login but cannot figure out how to get the device to store its ID there.
Any help would be much appreciated
You can get the device id using the following line of code:
String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
So beside the other user informations that you have, now you can also store the device id.
you can get Unique Device ID from System using ,
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = telephonyManager.getDeviceId();
you also have to add, following permission in manifest,
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
In my opinion, the currently best choice would be Settings.Secure.ANDROID_ID
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
For other solutions check this blog post : https://android-developers.googleblog.com/2011/03/identifying-app-installations.html
I am considering having my own website to sell my android app. After someone purchase my app I want that user's device id to be stored on my server so that when my app sends licensing data to my server, I have that device's id already store there. My app will verify that device id and will allow further access to the app.
So my question is, that is there any way I could fetch the unique device id of the device which actually pays for my app on my website??
Every answer is appreciated.
you can use this code :
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
but you have to use it at your own risk!
and I think it's no longer unique from android 4.2
You can use this:
TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService (Context.TELEPHONY_SERVICE);
String tmDeviceId = "" + tm.getDeviceId();
Can someone tell me if the code I have been using is the proper way to get the unique id? I am suspecting i may have dupes out there and this could be causing issues on an administrative level in my company...
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String UDID = tm.getDeviceId();
It is the proper way to call getDeviceId(). That may not be a unique identifier, since not all devices are phones and some phones have bugs. See this Android Developers Blog post for more details.
If you want a unique identifier for android there is tons of issues that you will see comes up with a simple google search. Similar to what CommonsWare mentioned.
However you can still get a unique identifier. The real question is what you want to identify. Either the user, or the device?
If you want to identify the particular user:
You want to IMSI value.
final TelephonyManager tm = (TelephonyManager)context`.getSystemService(Context.TELEPHONY_SERVICE);
String UDID = tm.getSubscriberId()
If you want to identify the hardware then you want the IMEI value:
final TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String UDID = tm.getDeviceId()
Now: I would recommend going with the getDeviceID() option as it has less privacy implications.
But you can take it a step event further and hash this value before storing it.
However, if you can't get a proper value returned, you could always do something like get the user to enter their phone number, and verify it through an sms. Then use that as an identifier.
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.
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.