I want to clear all the notification present in my device, notifications from other apps also.
I tried using:
mNotificationManager = (NotificationManager) getSystemService(TestActivity.NOTIFICATION_SERVICE);
mNotificationManager.cancelAll();
but of no good. Whereas in another test from where i am sending notifications this code works.
Is it not permitted to delete notifications from other applications ?
You can't cancel notifications from other apps- its done that way to prevent malicious apps from hiding other applications.
Related
I am using rooted device and i want to clear the other apps notification programatically from the status bar.
I tried this :
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
but this is not working in my tablet
It seems that since API 18, this method (notificationManager.cancellAll()) no longer works as expected, but I'm not sure about it. It looks like you need to create listener, which will listen when notifications are created and cancelled, store their objects somewhere and then you'll be able to remove objects and cancel notifications.
Check out this answer for details: https://stackoverflow.com/a/31233518/1150795.
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.
I'm using NotificationListenerService to read the notifications posted by other apps. In onNotificationPosted I get the deleteIntent of the notification and call deleteIntent.send() to remove the notification. This doesn't work for notifications posted by some apps! I have tried removing them using cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId()), but this also fails to remove them.
When swiping a notification on a phone or on a watch removes the notification from the phone, I expect firing deleteIntent explicitly, remove the notification as well.
Any ideas on why some notifications can't be removed?
The FLAG_NO_CLEAR has been set which prevents the notification from being cancelled.
While setting up the VPN connection in android phone, a system level notification with 'key' icon is generated by android system automatically. I am building an App which requires to set up a TUN interface internally but I am afraid of this notification which will be shown in notification bar by android system. I do not want android system to show up this notification to user.
Secondly a warning message "Attention" is also popped up while setting up a VPN connection. Again this message is also generated by android system.
I wanted my app to run quietly without showing any warning message and notification in notification bar. Any idea on how this thing can be achieved ??
Thanks
You cannot remove or disable it without changing the ROM. It is an android feature.
May be you should try something like How to cancel Android notifications or How to properly clear all notification once clicked in two words - something like this:
// Clear all notification
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
You can use the Xposed plugin NotifyClean to remove any notification, even the android system notify.
If you want to do it from source, viewing their source code may help.
From reading about wearable-notifications documentation, it doesn't seem possible to programmatically stop my app's notifications from appearing on the connected wearable device. I can add an my app to 'muted' apps' list using the Android Wear app on the handheld; however, I would like to do this using code. Please let me know if you've figured this out.
Additionally, is it possible to show a completely different notification on the phone and on the wearable, instead of just having a different set of notification actions on the wearable?
Thank you for your responses!
Using setLocalOnly(true), it is possible to display the notification only on phone. This, in effect, programmatically mutes your app - your app's notifications do not appear on the connected devices.
To create completely different notifications for phone and wearable, we can write a companion wearable app that displays the custom notification. The phone notification is then stopped from appearing on wearable using setLocalOnly(). I haven't tried the 'stacking' mentioned by Maciej Ciemięga yet.
(Added this as an answer for the benefit of those who might miss the comments on the accepted answer.)
First question:
I'm afraid muting apps from code is not possible.
Second question:
It is possible to show different notifications on phone and watch.
You can do it by implementing a wearable application and show local (setLocalOnly()) notifications separately on watch and phone (+ sync them with the phone using DataApi).
Alternatively you can make use of group feature of Android Wear framework. It's basically created to post many (grouped) notifications on wearable device and one summary notification on phone. But using this mechanism you can also post one (summary) notification on your phone and second notification only on wear.
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// This notification will be shown only on phone
final NotificationCompat.Builder phoneNotificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title phone")
.setContentText("Text phone")
.setGroup("GROUP")
.setGroupSummary(true);
// This notification will be shown only on watch
final NotificationCompat.Builder wearableNotificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title wearable")
.setContentText("Text wearable")
.setGroup("GROUP")
.setGroupSummary(false);
notificationManager.notify(0, phoneNotificationBuilder.build());
notificationManager.notify(1, wearableNotificationBuilder.build());
This way you can create "stack" with one notification only (+ summary notification of course). The stack with one notification will appear only on watch and the summary notification will appear only on phone - so this is what you want to achieve:)
Please read more about grouping (stacking) notifications here:
https://developer.android.com/training/wearables/notifications/stacks.html