Brief : In parse installation table device token is not added properly when I use new GCM API. right now following type of device token added into Parse installation table.
DeviceToken : |ID|1|:crGctxOB068:APA91bFgPRehabJcm9CYdS948iqX2_ppLj02CtbzmEHR0cfbuPooq5F--hqqvR9AH-Ez6MWMQON1Toc2DiNJTNdpRc3nmm3ukIpWJ1jHaXq0Iug6MoHbmKb9U0ak2CrKznkpKnPY5_Jp
Detailed description :
I have used new GCM api to get registration id. I need that regId for internal use.
I have used code from following link of google: Google cloud messaging android.
I have noted one point. when ever I start app parse get deviceToken properly. After login I am updating "user" field using following code in onCreate of mainActivity
ParseACL acl = new ParseACL();
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(true);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.setACL(acl);
if (ParseUser.getCurrentUser() != null) {
installation.put("user", ParseUser.getCurrentUser());
}
installation.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.e("installation", "success");
Log.i("parse", "token after save : " + ParseInstallation.getCurrentInstallation().getString("deviceToken"));
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Log.e("error: ", e.getLocalizedMessage());
e.printStackTrace();
} else {
Log.e("subscribed: ", "to broadcast channel");
Log.i("parse", "token after subscribe : " + ParseInstallation.getCurrentInstallation().getString("deviceToken"));
}
}
});
} else {
Log.e("installation", "failed");
e.printStackTrace();
}
}
});
Generally when above code run deviceToken got changed to Above mentioned token which seems wrong. So My push notification is not working.
I have solved issue.
I need to pass GCM device token to other webservice so I have used following code to get token from GCM.
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String token = instanceID.getToken(CommonUtils.SENDER_ID,
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
After getting token from this code parse's deviceToken changed. So instead of using above code I have used following code to get deviceToken and it solved the issue.
ParseInstallation.getCurrentInstallation().getString("deviceToken");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With