Reputation: 135
I am trying to implement push notifications and I got notifications too. But now I need to notifications in notification bar when switched on. I.e. if I got notification when mobile is on at time we did not see notification that is in notification area, if device shutdown then when I switched on the mobile, at time need to get that notification on notification bar and I have also another requirement, i.e. if I remove notification in notification area then after 10 minutes I need get that notification in notification area/ bar.
How can I accomplish this?
Upvotes: -1
Views: 111
Reputation: 546
Easy, right :)
Upvotes: 3
Reputation: 1794
You can use PendingIntent with 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());
}
And remember set WAKE_LOCK permission in your manifest file:
<uses-permission android:name="android.permission.WAKE_LOCK" />
Upvotes: 1
Reputation: 7759
To do stuff on boot register a BroadcastReceveiver
to BOOT_COMPLETED
in your manifest.
To do stuff after a certain time use AlarmManager
.
Upvotes: 0