알림 그룹을 구성해야합니다. 예를 만들었습니다 enter link description here스태킹 알림이 작동하지 않습니다.
하지만 내 고지는 그룹화되지 않았습니다. 내가 뭘 잘못 했니?
내 코드 :
는private static int id =0;
final static String GROUP_KEY_GUEST = "group_key_guest";
private static void generateNotification(Context context, String message) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Intent intent = new Intent(context,MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_stat_gcm)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm))
.setTicker("New Message")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("Message")
.setContentText(message)
.setGroup(GROUP_KEY_GUEST)
.build();
notificationManager.notify(id++, notification);
}
메서드 호출 :
@Override
protected void onMessage(Context context, Intent intent) {
Log.d(TAG, "Поступило сообщение: " + intent.getExtras());
String message = intent.getStringExtra("content");
generateNotification(context, message);
}
편집, 전체 코드 : 이 내가
package com.managment.pavel.managmentgradle;
public class GCMIntentService extends GCMBaseIntentService {
private static int id =0;
final static String GROUP_KEY_GUEST = "group_key_guest";
NotificationManagerCompat notificationManager;
public GCMIntentService() {
super(SENDER_ID);
notificationManager = NotificationManagerCompat.from(getApplicationContext());
}
@Override
protected void onMessage(Context context, Intent intent) {
String message = intent.getStringExtra("content");
generateNotification(context, message);
}
@Override
protected void onError(Context context, String s) {
Toast.makeText(context,"Error",Toast.LENGTH_LONG).show();
}
@Override
protected void onRegistered(Context context, String registrationId) {
ServerUtilities.register(context, registrationId);
}
@Override
protected void onUnregistered(Context context, String registrationId) {
ServerUtilities.unregister(context, registrationId);
}
private void generateNotification(Context context, String message) {
Intent intent = new Intent(context,MyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notification = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_stat_gcm)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_stat_gcm))
.setTicker("Новое сообщение")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("Сообщение")
.setContentText(message)
.setGroup(GROUP_KEY_GUEST)
.build();
notificationManager.notify(id++, notification);
}
}
의 설명서를 참조하십시오(). –
어쩌면 어리 석었지만 나는 할 수 없다. 공용 클래스 GCMIntentService는 GCMBaseIntentService를 확장합니다. { private static int id = 0; final static String GROUP_KEY_GUEST = "group_key_guest"; NotificationManagerCompat notificationManager; public GCMIntentService() { super (SENDER_ID); notificationManager = NotificationManagerCompat.from (getApplicationContext()); –