Reputation: 308
I setup GCM and it works fine. I get notifications from the server and they are shown to the client. The problem is, GCM creates its own notification and wont let me make a custom one. I followed this guide: https://github.com/codepath/android_guides/wiki/Google-Cloud-Messaging.
Here is my service code:
public class GcmMessageHandler extends GcmListenerService {
public static final int MESSAGE_NOTIFICATION_ID = 435345;
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
createNotification(from, message);
}
private void createNotification(String title, String body) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true);
Intent resultIntent = new Intent(this, RouteActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(RouteActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}
}
Anything helps.
Upvotes: 0
Views: 217
Reputation: 73721
from the docs
Message payload is optional. If you are including a payload in the message, use the data parameter to include your custom key/value pairs. The client app handles the data payload for display or other processing purposes.
The notification parameter with predefined options indicates that GCM will display the message on the client app’s behalf if the client app implements GCMListenerService on Android, or whenever the notification message is sent to an iOS device. The app server can send a message including both notification and data payloads. In such cases, GCM handles displaying the notification payload and the client app handles the data payload. For more information and examples, see
in other words if you send in your payload a notification
tag GCM will create a notification for your app
https://developers.google.com/cloud-messaging/server
Upvotes: 2
Reputation: 663
Custom layout for notifications in Android, if that's what you mean: Create custom notification, android
Upvotes: 0