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 = "Hello World!"; notification.setLatestEventInfo(context, contentTitle, contentText, null); mNotificationManager.notify(HELLO_ID, notification);
Every notification should respond to a tap, usually to open an activity in your app that corresponds to the notification. To do so, you must specify a content intent defined with a PendingIntent object and pass it to setContentIntent() . . setContentText("Hello World!")
Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.
Push notifications are messages that pop up on a user's mobile phone or desktop device via their chosen web browser. These little banners slide into view — whether or not your app or website is open.
What are push notifications? A push notification is a message that pops up on a mobile device, such as a sports score, an invitation to a flash sale or a coupon for downloading. App publishers can send them at any time, since users don't have to be in the app or using their devices to receive them.
You may pass the parameter
PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)
instead of
null
on
notification.setLatestEventInfo(context, contentTitle, contentText, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With