Skip to content

Commit 92b6162

Browse files
author
Devendra
committed
gcm demo app changes
1 parent 343dfb4 commit 92b6162

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ protected void onHandleIntent(Intent intent) {
5050
MESSAGE_TYPE_MESSAGE.equals(messageType)) {
5151
Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
5252
// Post notification of received message.
53-
sendNotification("Received: " + extras.toString());
53+
if (extras != null && extras.get("message") != null) {
54+
sendNotification(extras.get("message").toString());
55+
}
56+
5457
Log.i(TAG, "Received: " + extras.toString());
5558
}
5659
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ public class MainActivity extends Activity {
4747
GoogleCloudMessaging gcm;
4848
SharedPreferences prefs;
4949
Context context;
50-
String regId;
5150
public static String SENDER_ID;
5251
public static String REG_ID ;
5352
private static final String APP_VERSION = "3.6.1";
5453

5554
String PUBLISH_KEY = "demo";
5655
String SUBSCRIBE_KEY = "demo";
57-
String CIPHER_KEY = "demo";
56+
String CIPHER_KEY = "";
5857
String SECRET_KEY = "demo";
5958
String ORIGIN = "pubsub";
6059
String AUTH_KEY;
@@ -237,6 +236,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
237236
return true;
238237
case R.id.option27:
239238
gcmRegister();
239+
pubnub.setGcmRegistrationId(REG_ID);
240240
return true;
241241
case R.id.option28:
242242
gcmUnregister();
@@ -461,7 +461,7 @@ private Map<String,String> getCredentials() {
461461
map.put("PUBLISH_KEY", prefs.getString("PUBLISH_KEY", "demo"));
462462
map.put("SUBSCRIBE_KEY", prefs.getString("SUBSCRIBE_KEY", "demo"));
463463
map.put("SECRET_KEY", prefs.getString("SECRET_KEY", "demo"));
464-
map.put("CIPHER_KEY", prefs.getString("CIPHER_KEY", null));
464+
map.put("CIPHER_KEY", prefs.getString("CIPHER_KEY", ""));
465465
map.put("AUTH_KEY", prefs.getString("AUTH_KEY", null));
466466
map.put("ORIGIN", prefs.getString("ORIGIN", "pubsub"));
467467
map.put("UUID", prefs.getString("UUID", null));
@@ -577,21 +577,21 @@ private String gcmRegister() {
577577
return null;
578578
}
579579

580-
String regId = getRegistrationId(context);
581-
582-
if (TextUtils.isEmpty(regId)) {
580+
String REG_ID = getRegistrationId(context);
581+
pubnub.setGcmRegistrationId(REG_ID);
582+
if (TextUtils.isEmpty(REG_ID)) {
583583

584584
registerInBackground();
585585

586586
Log.d("RegisterActivity",
587587
"registerGCM - successfully registered with GCM server - regId: "
588-
+ regId);
588+
+ REG_ID);
589589
} else {
590-
Toast.makeText(getApplicationContext(),
591-
"RegId already available. RegId: " + regId,
592-
Toast.LENGTH_LONG).show();
590+
//Toast.makeText(getApplicationContext(),
591+
// "RegId already available. RegId: " + REG_ID,
592+
// Toast.LENGTH_LONG).show();
593593
}
594-
return regId;
594+
return REG_ID;
595595
}
596596

597597
private String getRegistrationId(Context context) {
@@ -631,12 +631,12 @@ protected String doInBackground(Void... params) {
631631
if (gcm == null) {
632632
gcm = GoogleCloudMessaging.getInstance(context);
633633
}
634-
regId = gcm.register(SENDER_ID);
634+
REG_ID = gcm.register(SENDER_ID);
635635
Log.d("RegisterActivity", "registerInBackground - regId: "
636-
+ regId);
637-
msg = "Device registered, registration ID=" + regId;
636+
+ REG_ID);
637+
msg = "Device registered, registration ID=" + REG_ID;
638638

639-
storeRegistrationId(context, regId);
639+
storeRegistrationId(context, REG_ID);
640640
} catch (IOException ex) {
641641
msg = "Error :" + ex.getMessage();
642642
Log.d("RegisterActivity", "Error: " + msg);

0 commit comments

Comments
 (0)