【发布时间】:2019-01-20 04:34:08
【问题描述】:
但是,即使没有将子项添加到数据库中,此代码也会在每天多次启动应用程序时显示通知
请帮我解决这个问题,我试过使用onDatabaseChange 方法但同样的事情发生了
if (mChildEventListener == null) {
mChildEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Intent intent = new Intent(getBaseContext(),MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mnotificationBuilder = new NotificationCompat.Builder(getBaseContext())
.setSmallIcon(R.mipmap.ic_chat)
.setContentTitle("You may have New Messages !!")
.setContentText("Check Chat Room > Received > New Message")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
notificationManager.notify(0, mnotificationBuilder.build());
}
【问题讨论】:
标签: android firebase-realtime-database android-service