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.
Related
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
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.
Basically, I am wondering if it is possible to create two different notifications and how - one for Android Device and other for Android Wear?
For example: I want to have just setContentText, but on Android device I want setContentTitle and setContentText
There is currently no possibility to show notification just on Wear (like setLocalOnly with device only - look for more).
I think the Synchronized Notifications sample that comes with the Android Wear SDK may be useful to look at. It gives three simple types of notifications:
(1) A phone-only notification
(2) A watch-only notification
(3) A pair of synchronized phone and watch notifications where the content shown
on the watch notification is different from the one on the phone. They are
synchronized in the sense that dismissing one results in dismissal of the
other one; all based on the Data Layer apis.
I think the third use case is most relevant to you.
Officially it is not possible to create two different notifications for wear and the phone without writing your own Android Wear App extension. It is only possible to define a notification that is only shown on the phone with NotificationCompat.Builder.setLocalOnly(true)
To create a Notification that is only shown on a Wear Device however you can (at the moment) add the Notification to a group with NotificationCompat.Builder.setGroup(randomGroupKey) and omit the display of a group summary notification. If a notification belongs to a group it is not displayed on the phone because the phone will only show the summary notification. If there is no summary you get a notification for your watch only. Just generate a random group key for every watch only notification.
Officially it is only possible to create a notification that looks different on a smartwatch.
For this use a WearableExtender. For example this code snippet:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(getString(R.string.smaple_notification_title));
builder.setSmallIcon(R.drawable.ic_message);
builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ActivateActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
extender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notif_background));
extender.setContentIcon(R.drawable.ic_message);
extender.setHintHideIcon(true);
extender.extend(builder);
builder.setPriority(NotificationCompat.PRIORITY_LOW);
builder.setContentText(notificationText);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon));
notificationManager.notify(messageIndex, builder.build());
Sets a special background for the notification, hides the app icon that is normally displayed on the notification, and adds a new icon to the preview of your Notification in the "screen off" mode of the watch.
I don't know if there is a way to do exactly what you want but I try to use stack & summary to bypass this: an contentText only notification has been hidden by a summary notification with contentText and contentTitle. On the Android Wear however summary is not being displayed but all the stacked notification (in your term is the notification with only contentText) can be shown.
Yes, It is possible. Steps -
Intercept your Notifications on Handheld by implementing BroadcastReceiever
Generate Notification for Handheld using NotificationBuilder - use setLocalOnly to duplicating it with Wearable
Send Notification data in Message to Wearable - using MessageApi
Extract receieved data & generate Notification for Wearable
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.