-5

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

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:

  1. https://stackoverflow.com/a/2175688/819355
  2. https://stackoverflow.com/a/19444640/819355
marmor
  • 27,641
  • 11
  • 107
  • 150