3

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
Alex
  • 1,237
  • 3
  • 18
  • 29
  • Sounds like a good way to do it might be to try a few different things and see if they agree. – Wug Jul 10 '12 at 13:38
  • One point: I don't think it's necessary to have a Google account to use an Android phone, so that's unlikely to be a foolproof method. – Spinner Jul 10 '12 at 13:58
  • This is right. I'm aware i will never succeed in extracting the user phone number in the 100% of cases. I'm just building a function that tries as many methods as possible. Actually my function try to extract it from the SIM, if it fail the fucntion could try the SMS method and as last chance the Google account method... it is just to improve the probability of succeed for this goal. – Alex Jul 10 '12 at 14:13
  • 1
    See my answer here that expands on the topic: http://stackoverflow.com/questions/10695601/msisdn-is-it-a-sim-card-data-why-all-the-provided-function-from-blackberry-a/11135551#11135551 – darryn.ten Jul 10 '12 at 22:25
  • Hi alex, if your method works - can you please post your code here? thanks! – Erez Dec 26 '12 at 23:14
  • Hi @Erez . i'm sorry but i haven't found a working solution for the problem... sorry. – Alex Dec 27 '12 at 10:42
  • Sorry to ask again, but any updates on a solution Alex? as we are in the same situation! – Sam Palmer Feb 15 '13 at 14:55
  • @SamPalmer Sorry... haven't actually found any solution. – Alex Feb 15 '13 at 23:18
  • No worries, we came to the same conclusion and have had to build in sms authentication on application install instead. Cheer though, such an annoying issue! – Sam Palmer Feb 16 '13 at 12:53
  • Do you intend something like sending an SMS to the user with a code like in verification email? – Alex Feb 16 '13 at 18:58

2 Answers2

0
private String getMyPhoneNumber() {
  TelephonyManager mTelephonyMgr;
  mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  return mTelephonyMgr.getLine1Number();
}

Try this, I'm from Poland, and it works well.

dda
  • 6,030
  • 2
  • 25
  • 34
Dawid Sajdak
  • 3,064
  • 2
  • 23
  • 37
  • Dear, i wrote in my first line that i already tried this solution and here in my country this return NULL because the SIM have the phone number field set to by the provider... – Alex Jul 10 '12 at 13:54
0

The solution: The package name of the manifest is de.org.limindo.limindo2 but the package of the apk is de.org.limindo2 .....