android-notifications

NotificationListenerService onNotificationPosted() called multiple times for single Notification when it is part of grouped notification

浪尽此生 提交于 2019-12-03 06:04:05
I am trying to listen to android notification using NotificationListenerService. I have tested the code with Whatsapp and Hangout notifications. Scenario 1: 1 Message from 1 User I receive onNotificationPosted() call once (which is correct) Scenario 2: 2 Messages from 1 user I receive onNotificationPosted() call twice accordingly (which is correct) [I get one more which is a grouped notification with the summary text which is same as the text. I ignore this notification manually] Scenario 3: multiple messages from multiple users I am receiving onNotificationPosted() call multiple times as per

android notification in background if app closed?

家住魔仙堡 提交于 2019-12-03 05:55:15
问题 I am trying to display a notification in the Android notifications bar even if my application is closed. I've tried searching, but I have had no luck finding help. An example of this is a news application. Even if the phone screen is off or the news application is closed, it can still send a notification for recent news and have it appear in the notification bar. How might I go about doing this in my own application? 回答1: You have to build a Service that handles your news and shows

Why do we use the TaskStackBuilder?

≯℡__Kan透↙ 提交于 2019-12-03 05:36:13
问题 Why do we use the TaskStackBuilder when creating a notification? I do not get the logic behind it. Can someone please explain. public void showText(final String text){ Intent intent = new Intent (this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification =

Android notification setSound is not working

淺唱寂寞╮ 提交于 2019-12-03 05:16:42
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 <resource-file src="src/android/res/unysound.mp3" target="res/raw/mysound.mp3" />' . Opening the APK as a zip archive I see that the mp3 file has in fact ended up in `res/raw/mysound.mp3'. - When building the notification I do the following Notification notification = new Notification.Builder(context) .setDefaults(0) //turns off ALL defaults .setVibrate(vibrate) /sets to vibrate ....

Adding a terminate playback button using Android L Notification.MediaStyle

不打扰是莪最后的温柔 提交于 2019-12-03 05:13:25
I want to create a Media Playback notification using the new Android L MediaStyle template. Now, I succeeded doing so perfectly well for actions like previous, play, pause, next (by using addAction() , but I couldn't find a way to add a "close" button like in the Android Notifications Documentation screenshot: Is there a neat way to achieve this? I want the "close" button to terminate the currently playing playback, clear the playback notification, and be located as in the attached screenshot. UPDATE When using the Support Library's version of this notification style, i.e. NotificationCompat

Can FCM notification on Android overwrite previous one?

我们两清 提交于 2019-12-03 04:32:00
I'm using FCM to send notifications to Android devices. When the app is in background, if I send 10 notifications, the devices will show up 10 entries on the notification bar. I want FCM to make only one entry on notification bar, i.e. the newer one will overwrite old ones. I don't find a key to set this at https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream . Is there a way to do, or it is impossible? Thanks. To achieve this, in your notification payload, use the tag key { "notification" : { "title" : "Notification Title", "body" : "Notification Body", "tag" : "your

Notification throws error when using vector drawables

不羁的心 提交于 2019-12-03 04:15:13
问题 I get the following exception when I use a vector drawable to set the small icon for a notification : android.app.RemoteServiceException: Bad notification posted from package com.qbes.xxx: Couldn't create icon: StatusBarIcon(pkg=com.qbes.xxxuser=0 id=0x7f020082 level=0 visible=true num=0 ) Here is my code : mNotificationBuilder = new android.support.v4.app.NotificationCompat.Builder(this) .setDefaults(android.support.v4.app.NotificationCompat.DEFAULT_LIGHTS) .setSound(null) .setSmallIcon(R

Oreo - Foreground service does not show foreground notification

蓝咒 提交于 2019-12-03 04:14:52
问题 So far, I've adjsuted my code to use ContextCompat.startForegroundService(context, intentService); to start my service. This way, it works on android < 26 and on android 26 (Oreo) as well. I still see a difference, in android oreo I don't see my custom foreground notification (I only see the "app is running in the background" notification). Do I have to adjust anything there as well? My service looks like this: public class BaseOverlayService extends Service { @Override public void onCreate()

Android: Manage multiple push notification in device of an app

让人想犯罪 __ 提交于 2019-12-03 03:17:30
I am developing an application in which i implemented Push notification functionality. My code of onMessage - GCMIntentService.java is: @Override protected void onMessage(Context context, Intent data) { String message = data.getExtras().getString("message"); displayMessage(context, message); generateNotification(context, message); } And code of generateNotification - private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context

Notification created by IntentService uses always a wrong Intent

倖福魔咒の 提交于 2019-12-03 01:14:53
Problem When the user presses Send "Button 1" (scroll down to see the construction of the app) a new Notification is created from the RefreshService . If the user presses this notification a MainActivity instance gets started and receives a String with the value Button 1 over the Intent . This value gets displayed. When the user presses now the Send "Button 2" a new Notification is created from the RefreshService . If the user presses this notification a MainActivity instance gets started and receives a String ALSO with the value Button 1 over the Intent . So as you can guess, normally there