4

I'm trying to get the token of my device. Thought this:

ParseInstallation parseInstallation = new ParseInstallation();
    String deviceToken = (String) parseInstallation.get("deviceToken");

would do the trick, but it doesnt, it returns null. Why?

Philip
  • 1,068
  • 3
  • 12
  • 21
  • u want to device token or id? – Farhan Shah Mar 28 '14 at 12:51
  • the device token, I want to save it in a database, so other devices can read it and send something to them. – Philip Mar 28 '14 at 12:52
  • 1
    Your `get`-call should be made after `Parse.initialize` according to [a similar question](https://www.parse.com/questions/android-how-do-i-get-the-devicetoken) on parse.com – Peterino Aug 04 '14 at 06:28

3 Answers3

9

Read this. Hope this helps.

http://android-developers.blogspot.be/2011/03/identifying-app-installations.html

OR

String android_id = Settings.Secure.getString(getApplicationContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);

OR

You can try getting the UUID or IMEI.

OR

If you're on the Parse Developer Console: enter image description here

Gene
  • 10,819
  • 1
  • 66
  • 58
1

There exists no stable unique ID for an Android device. You can maybe work with the ANDROID_ID but it will change on OS Upgrade/System reset

meredrica
  • 2,563
  • 1
  • 21
  • 24
  • so how do I get the device token to send a push over parse from device to device? – Philip Mar 28 '14 at 14:43
  • You get a unique push id for every registered device. just check the docs https://developer.android.com/google/gcm/index.html – meredrica Apr 01 '14 at 13:58
0

i'm using this code and it works for me! BUT device token is undefined for some devices in parse console (i don't know why!)

 String token = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Ali Sherafat
  • 3,506
  • 2
  • 38
  • 51