Objective: Notification should be auto cancelled on click of it and should open my activity(Pending Intent)..
I have a running code which works perfect in Android Devices expect Nokia-X. Here is the code:
Notification notification = new NotificationCompat.Builder(MainActivity.this)
.setContentTitle(MainActivity.this.getString(R.string.app_name))
.setContentText("text").setContentInfo("info").setTicker("Ticker text")
.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setWhen(System.currentTimeMillis())
.setLights(Color.YELLOW, 1, 2).setAutoCancel(true).build();
NotificationManager nm = (NotificationManager)MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, notification);
In case of Nokia-x device, It send notification. It open my activity on click of notification but notification stays in notification tray. It does not get clear on click.
Please help my out!!
It is just like Dr.Jukka said: Notifications cannot be programmatically removed from the Fastlane - only the user can remove content from the Fastlane:
"Currently all notifications are stored in the Fastlane even if the auto cancel flag is used. Do note that if your notification has a command visible from which user can dismiss/remove the notification manually, the notification is not removed from Fastlane. Notifications can only be removed from Fastlane manually by enabling the edit mode."
Furthermore, it does not make sense to have items such as notifications suddenly disappearing from the Fastlane since the purpose of the view is to display the user's/app's past activities.
Related
I have a foreground service in my app, whose persistent notification has a timer in it, which means that the notification is sent once per second to update the timer that is shown in the notification. This means that on some devices, where notifications are set to either wake the screen entirely or show a dark version on the screen briefly, the screen is constantly awake.
Is there a way to send the notification in a way that it won't wake up the screen? Setting it as a silent notification on the device fixes this, but the point of a foreground service notification is that it's prominent on the device, so this isn't a great solution, and not all users would know to do that.
This is how I'm building the notification:
NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Currently Reading")
.setSound(null)
.setContentIntent(TaskStackBuilder.create(this).run {
addNextIntentWithParentStack(timerIntent)
getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
})
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
Have you tried updating the notification instead? And use setOnlyAlertOnce()
"You can optionally call setOnlyAlertOnce() so your notification interupts the user (with sound, vibration, or visual clues) only the first time the notification appears and not for later updates."
Check this link
https://developer.android.com/training/notify-user/build-notification.html#Updating
setPriority(NotificationCompat.PRIORITY_DEFAULT)?
lower it, so wont be shown on lockscreen (android 7 and up)
and here we go with a small fix for this part:
setPriority(NotificationCompat.PRIORITY_LOW)
you can also add:
setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
but it'll also remove notification from lockscreen...
docs:
https://developer.android.com/training/notify-user/build-notification.html#lockscreenNotification
https://developer.android.com/training/notify-user/channels#importance
hope this helps =]
I am developing an Android app. In my app, I am doing push notification using Firebase. When I push from server, it shows notification in status bar in Android device. Pushing notification using Firebase is working fine.
I show notification like this in Android:
private void showMatchesNotification(String message)
{
notification = new NotificationCompat.Builder(getApplicationContext());
notification.setAutoCancel(true);
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setWhen(System.currentTimeMillis());
notification.setTicker(message);
notification.setContentTitle(getApplication().getResources().getString(R.string.app_name));
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra(MainActivity.FIELD_SELECTED_BOTTOM_TAB, MainActivity.BOTTOM_TAB_MATCHES);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),0,i,PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
NotificationManager nm = (NotificationManager)getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
nm.notify(3,notification.build());
}
The problem is when I show notification in Android, notification became junk in Clean Master app. Like below.
But when I tap on it, it is showing notifactions like this.
My question is, are notifications always marked as junk if Clean Master app is installed? Is there a way to push notification avoiding of becoming junks in Clean Master app? I want to show notification of my app in the status bar, and not in the junks. How can I do that?
Just disable the the 'junk notification" feature in CM. This is a feature you must have enabled in the first place, as it is not active on install. While I use CM, I've never enabled the 'junk notification' feature (might also be known as 'quiet notification"), I prefer to control notifications via each individual app setting. Otherwise, I don't really find them to be a problem.
When you enable Junk notification in CleanMaster app, it will put the notifications to junk of other apps. Click on the settings button in Notification cleaner on top right and you can see all apps which are enabled or disabled for notification cleaner. You can uncheck your app to prevent Cleanmaster from putting your notification to junk.
In Android, if a user sets "Show Notifications" of a specific App to off, is the notification still created? If yes, is it somehow possible to access these created but not shown notifications?
As an example, consider that to create a Status bar Notification, below code is used:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
And to POST this notification, below code is used:
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());
But since the "Show Notification" is OFF, above code don't show the Notification on Status bar. So as you can see, although the NotificationCompat.Builder has CREATED a Notification object/instance and filled it with other details such as Title or Text etc. you can NOT access it as it is NOT Allowed to POST by System because of user's preference settings.
Also, Since Android 4.1, users can turn off notifications of an app from application manager, but there is NO API to acheive the same from Application code (on Non-rooted device,that is). And It is not possible to disable notifications from other apps, and you can only control notifications generated by your own app.
Few more pointers that you must have in mind:
1.As a developer we have no way to know whether a call to notify was effective or not. So if I really need to check if the notifications are disabled for the current application there is NO Such setting for that in the API.
2.You really shouldn't concern yourself with it. Just assume your notification was successful. If the user has explicitly disabled your notifications, then he/she probably had good reason to do so, and your application should not care whether the notification was displayed or not
Hi i've used parse push notification in my android app.
i'm not using noraml notification. i've register parse push notification. The notification alert comes from server
device received the push notification successfully.
for example i've received 10 notification from server, if i open one notification on my device, the app has opened and the one notification has deleted.
My question is,
how to clear the other 9 push notification alert on status bar when open one notification..?
Does android.app.NotificationManager.cancelAll() not work?
If you need to do something very custom, you can use ParsePush to launch an Intent rather than creating a Notification. You can then use a BroadcastReceiver to create Notifications with non-standard behavior (i.e. selective stacking, dismiss all when one is interacted with, etc).
Use this in your launch activity:
String ns = getActivity().NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) getActivity().getSystemService(ns);
nMgr.cancelAll();
Use this in your Main Activity
NotificationManager nm = (NotificationManager) get SystemService(Context.NOTIFICATION_SERVICE);
nm.cancelAll;
I made an app that works in the place of the stock messages app. It's basically a popup that displays the text message when it comes in.
When a text message comes in, the phone obviously puts a notification in the notification tray. How do I clear this notification once the user has viewed my popup? When he views my popup, the message is marked as "Read" in the inbox, but the notification isn't cleared. How do I do this? Thanks!
In the notification builder use the setAutoCancel() method:
NotificationCompat.Builder builder = new NotificationCompat.Builder(
context);
builder.setAutoCancel(true);
You can include NotificationListenerService in your project which allows you to listen to all the Notifications that are posted on the phone.
After that you can use cancelNotification() method to clear the notifications you want to dismiss.
Note that user needs to explicitly grant your application Notification Access Permission in order for your application to access the notifications.