Android Wear应用程序在一段时间后停止接收通知

时间:2016-11-08 16:07:14

标签: android firebase firebase-cloud-messaging firebase-notifications

我正在使用Android Studio 2.1.3,我为智能手表制作了一个小应用程序,仅用于接收FCM通知。 问题是,在一定时间(一两个小时)后停止接收通知之前,每件事情都会很好。

通知处理程序:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Intent intent = new Intent(this, MainActivity.class);

    intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP );

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);

    notificationBuilder.setContentTitle("FCM NOTIFICATION");
    notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}

从PHP发送的通知:

{"collapse_key":"1734793905","delay_while_idle":false,"to":"__TOKEN__","priority":"high","time_to_live":83,"notification":{"title":"__MSG_TITLE__ ","body":"__MSG_BODY__","sound":true}}

Google Firebase响应(智能手表上未显示通知时相同):

{"multicast_id":76761069655130575608,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1478608765404313%e0e2d11fe0e2d89f"}]}

我非常感谢您提供的任何帮助。

0 个答案:

没有答案