Android parse push notification and new GCM generate the wrong device token and do not activate parsing notification

Brief . Nothing is added to the parser token when I use the new GCM API . now the next type of device token added to the Parse installation table.

DeviceToken: | ID | 1 |: crGctxOB068: APA91bFgPRehabJcm9CYdS948iqX2_ppLj02CtbzmEHR0cfbuPooq5F - hqqvR9AH- Ez6MWMQON1Toc2DiNJTNdpRc3nmm3ukIpWJ1jHaXq0Iug6MoHbmKb9U0ak2CrKznkpKnPY5_Jp


Detailed Description :

I used the new GCM api to get the registration id. I need regId for internal use.

I used the code from the following google link: Google cloud messaging android .

I noted one point. when ever i start parsing an application, get deviceToken correctly. After logging in, I update the user field using the following code in onCreate 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(); } } }); 

Usually, when the above code run deviceToken was changed to the aforementioned token, which seems wrong. So my push notification is not working.

+6
source share
1 answer

I solved the problem.

I need to transfer the GCM device token to another web service, so I used the following code to get the token from GCM.

  InstanceID instanceID = InstanceID.getInstance(getApplicationContext()); String token = instanceID.getToken(CommonUtils.SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); 

After receiving the token from this device, the code analysis has changed. So instead of using the above code, I used the following code to get the DeviceToken and solved the problem.

 ParseInstallation.getCurrentInstallation().getString("deviceToken"); 
+1
source

All Articles