Questions tagged [android-notifications]

A status notification adds an icon to the system's status bar (with an optional ticker-text message) and a notification message in the notifications window.

A notification is a user interface element that you display outside your app's normal UI to indicate that an event has occurred. Users can choose to view the notification while using other apps and respond to it when it's convenient for them.

Think of notifications as a news channel that alerts the user to important events as they happen or a log that chronicles events while the user is not paying attention. The user can expand the notification bar and by selecting the notification the user can trigger another activity. Notifications in Android are represented by the Notification class. To create notifications you use the NotificationManager class which can be received from the Activity via the getSystemService() method.

Useful links

4920 questions
40
votes
8 answers

How do I check whether a specific notification channel is enabled in Android Oreo?

I'm using the following call to check whether notifications are enabled: NotificationManagerCompat.from(getContext()).areNotificationsEnabled() However, if a user disables only the channel, I cannot know about it. How do I check whether a specific…
itzhar
  • 12,743
  • 6
  • 56
  • 63
39
votes
8 answers

Android notification setSound is not working

In my hybrid Cordova Android app targeting API 23+ I want to use a custom sound for notifications. To that end I have done the following In plugin.xml file for the single custom plugin I use in the app I declare
DroidOS
  • 8,530
  • 16
  • 99
  • 171
39
votes
1 answer

Adding button action in custom notification

I have made custom notification and there is a button in that, I want to perform two different functionalities on notification and button click. I look at many links but couldn't find the way to add button listener. Can anyone help. Here is my…
39
votes
5 answers

Listen to incoming Whatsapp messages/notifications

I'm working on a notification based app, for which I need to listen to incoming notifications. I've been able to listen to incoming calls, SMS, mail etc. I have no clue how to listen for pings or messages from friends on Whatsapp via code. Can this…
38
votes
4 answers

W/FirebaseMessaging: Missing Default Notification Channel metadata in AndroidManifest. Default value will be used

Our app now has targetSdkVersion 26 (Android 8) and the app uses FCM push notifications. When app is in the foreground state the push notification is working well. The issue appears while clicking the notification when the app is not in the…
38
votes
3 answers

Push notification works incorrectly when app is on background or not running

I am using Firebase Cloud Messaging to send push notifications. Here is my FirebaseMessageService: public class FireBaseMessageService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { …
38
votes
2 answers

Android: Grouped notifications and summary still shown separately on 4.4 and below

I want to implement stacked notifications on Android Wear To do that I create 1 summary notification and N individual notifications for each "item". I want only the summary to be shown on the phone. Here's my code: private void showNotifications()…
36
votes
3 answers

How to Dismiss/Cancel the status bar notification in android programmatically

I have created a status bar notification in android programmatically using the code given below with a particular id Notification notification; public static NotificationManager myNotificationManager; public static final int…
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
35
votes
4 answers

Android O - Single line Notification - like the "Android System - USB charging this device"

I would like to have an ongoing notification for my ForegroundService that requires as small place as possible. I like the "Android System - USB charging this device" style, but I cannot find any example how to achieve this. Can anyone point me in…
Sobvan
  • 1,376
  • 1
  • 15
  • 24
35
votes
8 answers

Can I test status bar notifications using Android's testing framework?

I have a class that sends a status bar notification in Android. I can't find a way to test whether the notification was sent or not, which makes it very hard to write any kind of useful unit test. Does anyone have a solution for this?
defrex
  • 15,735
  • 7
  • 34
  • 45
35
votes
4 answers

Bad notification posted from package Couldn't expand RemoteViews

I have a problem. Some times my service is forcefully closed with this logcat: 03-26 20:44:44.849: E/AndroidRuntime(12080): FATAL EXCEPTION: main 03-26 20:44:44.849: E/AndroidRuntime(12080): android.app.RemoteServiceException: Bad notification…
user2212515
  • 1,220
  • 1
  • 12
  • 10
34
votes
1 answer

Android - Calling methods from notification action button

I know that you can launch Activities from the action buttons using PendingIntents. How do you make it so that the a method gets called when the user clicks the notification action button? public static void createNotif(Context context){ ... …
34
votes
2 answers

How to send notification from handheld to wear to open Activity on wear device

I'm wondering if it is possible to send notification from handheld (android phone) to wear device to open Activity on wear device? What I want to do is as following. So far, I checked the following documents, but it's different from what I want to…
Poly
  • 1,053
  • 1
  • 11
  • 16
33
votes
5 answers

Android multiple line notification like Gmail app

I am trying to create a multiple line notification like the Gmail application does as shown in the image below (the 5 notifications grouped under one notification) I have tried various examples but can only seem to create single notifications like …
user3013243
  • 516
  • 1
  • 4
  • 19
33
votes
4 answers

Change Notification Layout

I decompiled my system music app (from Sony Ericsson for Android GB 2.3.7) because I want to change the notification layout. I found the method which creates the notification with this code: private void sendStatusBarNotification(Track…
Cilenco
  • 6,951
  • 17
  • 72
  • 152