Android App 没有消息提醒

Android 应用在后台的通知分为两种:
1、没有被杀掉,在 onMessage 事件中自行弹出通知窗口。ChatKit 的实现方式在:

2、被杀掉了,通过混合推送推送通知:
https://leancloud.cn/docs/android_push_guide.html#hash860147210

Android 应用是在后台的通知是通过onMessage的,而且也走了这个方法但是就是没有消息提醒

 public static void showNotification(Context context, String title, String content, String sound, Intent intent) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
        .setSmallIcon(context.getApplicationInfo().icon)
        .setContentTitle(title).setAutoCancel(true).setContentIntent(contentIntent)
        .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
        .setContentText(content);
    NotificationManager manager =
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    if (sound != null && sound.trim().length() > 0) {
      notification.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + sound);
    }
    lastNotificationId = (lastNotificationId > 10000 ? 0 : lastNotificationId + 1);
    manager.notify(lastNotificationId, notification);
  }

如果「通过onMessage」是触发了,说明消息已经送达了客户端。而为什么弹不出通知或者震动,推测是因为手机 ROM 对第三方 service 触发 notification 权限的管控。可以观察一下日志 log 里的相关 permission 报错线索,来查找如何解决。

但是你们的chatkit DEMO就可以正常触发,那估计是什么原因呢

找到问题了
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)替换为
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,"xxxxx")