deviceToken is always null on Android with Parse.com

1.6k Views Asked by At

ParseInstallation class returns deviceToken as null and also in Parse.com Installation table the installation is saved as empty deviceToken.

Using

Android application class onCreate:

@Override
public void onCreate() {
    super.onCreate();

    ParseCrashReporting.enable(getApplicationContext());
    Parse.initialize(this, "xx", "xx");
    ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");

            Log.d("my_app","DEVICE TOKEN: " + deviceToken);  // --> returns null string
        }
    });
 }
2

There are 2 best solutions below

3
On BEST ANSWER

Found the error. I had to change Parse permissions (allow adding fields) on Installation class and after that 'channels' field shown up and also deviceToken was saved.

Update:

You can confirm this on the app settings: Core > Data > _Installation > Security (button on toolbar)

Security settings for the _Installation class

By default it has access to create new fields but I had changed it.

1
On

You need to make sure that you include your build flavor in the package name as well, I recently had this problem and didn't realize for a long time until I added that.

i.e com.packname.flavor{debug, release, etc.}