Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - notification manager, having a notification without an intent

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); 
like image 488
Garbit Avatar asked Aug 12 '11 13:08

Garbit


People also ask

Which intent is employed for generating notifications in Android?

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!")

What is pending intent in Android notification?

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.

What is a mobile push notification?

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 is a push notification Android?

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.


1 Answers

You may pass the parameter

PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0) 

instead of

null 

on

notification.setLatestEventInfo(context, contentTitle, contentText, null);

like image 76
faradaj Avatar answered Sep 28 '22 23:09

faradaj