-1

我正在尝试实现推送通知,我也收到了通知。但是现在我需要在打开时通知栏中的通知。即,如果我在手机打开时收到通知,我们没有看到通知区域中的通知,如果设备关闭,那么当我打开手机时,有时需要在通知栏上获得该通知,我还有另一个要求,即,如果我在通知区域中删除通知,那么 10 分钟后我需要在通知区域/栏中获得该通知。

我怎样才能做到这一点?

4

3 回答 3

3
  1. 您需要将通知内容保存在某些位置,例如SharePreference
  2. 您在使用此意图启动设备时收听,“android.intent.action.BOOT_COMPLETED”,当广播接收器被触发时,您从步骤 1 中读取通知内容,再次触发通知。

简单,对:)

于 2016-05-17T15:37:19.790 回答
1

您可以将 PendingIntent 与FLAG_ONE_SHOT一起使用:

private void sendNotification(String from, String message) {
        Bundle bundle = new Bundle();
        Intent intent = new Intent(this, ChatActivity.class);
        intent.putExtra("INFO", bundle);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setContentTitle(from)
                .setSound(defaultSoundUri)
                .setContentText(message)
                .setSmallIcon(R.drawable.ic_notification)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, builder.build());
    }

并记住在清单文件中设置 WAKE_LOCK 权限:

<uses-permission android:name="android.permission.WAKE_LOCK" />
于 2016-04-07T07:16:59.287 回答
0

在你的清单中BroadcastReceveiver做引导注册的事情。BOOT_COMPLETED

一定时间后做东西使用AlarmManager

于 2016-04-07T07:01:09.490 回答