Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class MyGcmListenerService extends GcmListenerService {

private static final String TAG = "MyGcmListenerService";

private static final String EXTRA_DATA = "data";
private static final String EXTRA_WEATHER = "weather";
private static final String EXTRA_LOCATION = "location";

Expand All @@ -63,17 +62,11 @@ public void onMessageReceived(String from, Bundle data) {
// Not a bad idea to check that the message is coming from your server.
if ((senderId).equals(from)) {
// Process message and then post a notification of the received message.
try {
JSONObject jsonObject = new JSONObject(data.getString(EXTRA_DATA));
String weather = jsonObject.getString(EXTRA_WEATHER);
String location = jsonObject.getString(EXTRA_LOCATION);
String weather = data.getString(EXTRA_WEATHER);
String location = data.getString(EXTRA_LOCATION);
String alert =
String.format(getString(R.string.gcm_weather_alert), weather, location);
sendNotification(alert);
} catch (JSONException e) {
// JSON parsing failed, so we just let this message go, since GCM is not one
// of our critical features.
}
}
Log.i(TAG, "Received: " + data.toString());
}
Expand Down Expand Up @@ -107,4 +100,4 @@ private void sendNotification(String message) {
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
}
}