Skip to content

Commit 986aa48

Browse files
author
Devendra
committed
gcm demo app changes
1 parent 92b6162 commit 986aa48

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • android/examples/PubnubExample/src/com/pubnub/examples/pubnubExample10

‎android/examples/PubnubExample/src/com/pubnub/examples/pubnubExample10/MainActivity.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ private void init() {
428428
SENDER_ID = map.get("SENDER_ID");
429429
AUTH_KEY = map.get("AUTH_KEY");
430430
ORIGIN = map.get("ORIGIN");
431+
REG_ID = map.get("REG_ID");
432+
431433

432434
pubnub = new Pubnub(
433435
PUBLISH_KEY,
@@ -436,6 +438,7 @@ private void init() {
436438
CIPHER_KEY,
437439
SSL
438440
);
441+
pubnub.setGcmRegistrationId(REG_ID);
439442
pubnub.setCacheBusting(false);
440443
pubnub.setOrigin(ORIGIN);
441444
pubnub.setAuthKey(AUTH_KEY);
@@ -514,6 +517,9 @@ public void errorCallback(String channel,
514517
});
515518
} catch (PubnubGcmRegistrationIdMissingException e) {
516519
gcmRegister();
520+
Toast.makeText(getApplicationContext(),
521+
"GCM registration ID was not set. Auto registering. Try removing channel again.",
522+
Toast.LENGTH_LONG).show();
517523
}
518524
}
519525
});
@@ -550,6 +556,9 @@ public void errorCallback(String channel,
550556
});
551557
} catch (PubnubGcmRegistrationIdMissingException e) {
552558
gcmRegister();
559+
Toast.makeText(getApplicationContext(),
560+
"GCM registration ID was not set. Auto registering. Try adding channel again.",
561+
Toast.LENGTH_LONG).show();
553562
}
554563
}
555564
});
@@ -595,7 +604,7 @@ private String gcmRegister() {
595604
}
596605

597606
private String getRegistrationId(Context context) {
598-
String registrationId = prefs.getString(REG_ID, "");
607+
String registrationId = prefs.getString("REG_ID", "");
599608
if (registrationId.length() <= 0) {
600609
Log.i(TAG, "Registration not found.");
601610
return "";
@@ -647,9 +656,9 @@ protected String doInBackground(Void... params) {
647656

648657
@Override
649658
protected void onPostExecute(String msg) {
650-
Toast.makeText(getApplicationContext(),
659+
/*Toast.makeText(getApplicationContext(),
651660
"Registered with GCM Server." + msg, Toast.LENGTH_LONG)
652-
.show();
661+
.show();*/
653662
}
654663
}.execute(null, null, null);
655664
}
@@ -658,7 +667,7 @@ private void storeRegistrationId(Context context, String regId) {
658667
int appVersion = getAppVersion(context);
659668
Log.i(TAG, "Saving regId on app version " + appVersion);
660669
SharedPreferences.Editor editor = prefs.edit();
661-
editor.putString(REG_ID, regId);
670+
editor.putString("REG_ID", regId);
662671
editor.putInt(APP_VERSION, appVersion);
663672
editor.commit();
664673
}

0 commit comments

Comments
 (0)