I have an android game in play store and have around 150 active users.
I am adding leaderboard in the upcoming update
so that people can compete with each other.
My app does not require access to any specific permission.
However I want to know if there we can know the contact number of a user who downloads our app so that we can
send a congratulation message when someone reach at the
top of the leaderboard.
Can anyone please tell me how it can be done in Android and if yes, where can we view the number?
Asked
Active
Viewed 1,879 times
-5

Vadim Kotov
- 8,084
- 8
- 48
- 62

Shivam Sharma
- 7
- 1
1 Answers
0
There's no permission to get the user's phone-number, you can sometimes get it via:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
number = telephonyManager.getLine1Number();
But it's not guaranteed to work, and even when it works, in some rare cases, you'll get the wrong number.
You can request the user permission to get his/her email address, and maybe send them a congrats email instead, that's more appropriate IMHO, and more easily done.
UPDATE
The simplest way of getting a user's email, is to ask her, you can use Android AccountManager to either silently get all the accounts from the device, and pick one (requires GET_ACCOUNTS permission), or to ask the user to pick an account from his device's list of accounts (no permission required), See the following SO answers:

marmor
- 27,641
- 11
- 107
- 150
-
thank you,that's a nice idea.can you tell me the steps to implement in android studio please:D – Shivam Sharma Aug 14 '17 at 15:33