notificationmanager

Add a new notification when push notification receives (not replace old one)

柔情痞子 提交于 2019-12-03 09:28:50
问题 I am using push notification on my app. I used to display a notification when a push notification comes, if I send another notification (without clearing the previous notification)it replaces the new notification. This is the code I use NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence tickerText = "New notification Pending"; long time = System.currentTimeMillis(); Notification

In Android how can i know the current notification id to clear the notification

社会主义新天地 提交于 2019-12-03 08:32:27
Now in android i put this code in one activity to show notification when a button pressed. static int notificationCount = 0; then btnNotification.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent notificationIntent = new Intent(AlertsActivity.this,NotificationActivitty.class); PendingIntent pIntent = PendingIntent.getActivity(AlertsActivity.this,notificationCount,notificationIntent,Intent.FLAG_ACTIVITY_NEW_TASK); // Construct the notification Notification.Builder nBuilder = new Notification.Builder(AlertsActivity.this); nBuilder.setContentTitle(

How to properly clear all notification once clicked?

僤鯓⒐⒋嵵緔 提交于 2019-11-30 21:43:40
问题 I send a few notification on the notification bar, i wanted to clear all of it when one of the notification is clicked. For now I clear one by one by using Flag. I know notificationManager.cancelAll() could clear all the notification but where should i put so that i can trigger once one of the notification is clicked. private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager

android memory leak in notification service

≯℡__Kan透↙ 提交于 2019-11-30 04:58:18
I have a service which creates a notification and then updates it with certain information periodically. After about 12 mins or so the phone crashes and reboots, I believe it is caused by a memory leak in the following code to do with how I am updating the notification, could someone please check/advise me if this is the case and what I am doing wrong. onCreate: mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); createNotification: private void createNotification() { Intent contentIntent = new Intent(this,MainScreen.class); contentIntent.setFlags(Intent.FLAG

How to use notification with sound and vibration?

蓝咒 提交于 2019-11-30 00:02:43
How do you allow the device to vibrate or make a sound when a notification is launched. Ive heard of the FLAGS. But how would i use them for Sound and Vibration? Edit In Android v4 support library, there is NotificationCompat.Builder and the method setSound which will work if using that class instead. However, the info below will still work. Notification notif ... //create your notification notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_VIBRATE; That adds sound and vibrate. Always remember to check the docs. They have a LOT of answers, such as this one:

android memory leak in notification service

早过忘川 提交于 2019-11-29 02:32:45
问题 I have a service which creates a notification and then updates it with certain information periodically. After about 12 mins or so the phone crashes and reboots, I believe it is caused by a memory leak in the following code to do with how I am updating the notification, could someone please check/advise me if this is the case and what I am doing wrong. onCreate: mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); createNotification: private void

NotificationManager.cancel(id) is not working inside a broadcast receiver

别说谁变了你拦得住时间么 提交于 2019-11-29 02:02:14
Android: I am trying to cancel a notification from the notification bar after a package being installed. What I am doing is the following: public class MyBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "MyBroadcastReceiver"; @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (Intent.ACTION_PACKAGE_ADDED.equals(action)) { Uri data = intent.getData(); //some code goes here //get the id of the notification to cancel in some way notificationhelper._completeNotificationManager.cancel(id); } } } where public class

Android - notification manager, having a notification without an intent

谁都会走 提交于 2019-11-27 13:03:41
I would like to be able to fire a notification to alert the users about a timer that has finished, however i do not wish to have an intent when you click the notification. I've tried passing in null for the intent String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon = R.drawable.icon; CharSequence tickerText = "Hello"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); CharSequence contentTitle = "My notification"; CharSequence contentText =

How to set click listener for notification?

丶灬走出姿态 提交于 2019-11-27 12:46:31
I am using the following code to launch a notification when a Service is started Via AlarmManager: nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "App"; CharSequence message = "Getting Latest Info..."; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.icon, "Getting Latest Info...", System.currentTimeMillis()); notif.setLatestEventInfo(this, from, message, contentIntent); nm.notify(1, notif); How do I set an intent for this item so that when the user clicks on

Multiple notifications to the same activity

十年热恋 提交于 2019-11-27 06:57:58
I have an activity that is being opened from the notification bar, but when I do NotificationManager.notify(...) , I'm giving to the intent a different bundle, so that each notification opens the same activity, but obtaining from the DB other information each other. But when I try to enter to any of the notifications (for example there are 3 notifications), they all send me to the activity with the same bundle that the last one. After trying with some Flags, I really don't know where is the problem (some flags makes the notification enter to the activity with the first bundle). I'm following