Strange allow/deny question on Huawei 5.1 phone when showing notification - android

So it turns out that Huawei phones with 5.1 can't display MediaStyle notifications so while fixing that, I made a very simple notification test and I get a strange question asking Allow App Name to push messages to the notification panel.
I don't use push in any way, in fact the screenshot below is for an app that all it does is show a sample notification, nothing else.
How can I make it not show that?
This is the code:
Notification notification = new Notification.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("Track title")
.setContentText("Artist - Album")
.setOngoing(true)
.addAction(R.drawable.ic_add_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_android_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_archive_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_arrow_back_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_aspect_ratio_black_24dp, "fwd", pi)
.addAction(R.drawable.ic_fast_forward_black_24dp, "fwd", pi)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.vectors_525058875))
.setAutoCancel(false)
.build();
notificationManager.notify(300, notification);
This is the screenshot.
What am I doing wrong? I tried taking out all the actions, that didn't help. Took out title and context, that didn't help. Took out large icon, auto cancel, ongoing, etc, didn't help.
Please note that I am not using Push in any way and this doesn't seem to be related to that. Also I a using the support compat libraries to make my notification but on this example I didn't just to make sure that wasn't the issue.

Huawei's version of the Android OS has a custom feature that tries to spot apps doing annoying numbers of notifications.
Don't focus on the word "push". It doesn't mean "push notifications" in the technical sense of coming from the internet. It just is a verb, they could have said "allow app to create notifications" or "allow app to cause notifications" it's the same meaning.
Anyway, this is an OS feature, there is nothing you can do to avoid it except make sure you aren't spammy with your notifications. Unfortunately during development and testing you will often be triggering a lot of notifications, and the OS will detect your app is spammy. Don't worry about it. As long as your app works well for normal users it shouldn't happen.

It's Huawei customized Android OS feature. Long story short, you can't disable it.
I saw it a lot when I test my app. Huawei OS thinks your notification might annoy the end user(yourself, in this case) because it happened a lot.
You don't have to concern it😀

Your use deprecated constructor. Your must specify channel. Like this:
Notification.Builder builder = new NotificationCompat.Builder(context,"MyPerfectApplication")
Otherwise you use unknown chanel, possible you try to push in system channel.

it's indeed a custom check of EMUI, which enables the user to decide whether or not to have these custom notifications being pushed into the default notification channel, before a single one of these notifications had ever been displayed, when the first push is being attempted. it generally controls the notification settings of your app on Huawei devices, from within that notification panel. system & vendor applications are permitted to push notifications by default and therefore it won't ever ask the user for a double confirmation there. this has nothing to do with excessive notifications, because it is a precondition to even have these notifications pushed, no matter the amount.

Related

How to make an Android notification "persistent"?

On my Android 10 device, I see that the LastPass app is able to create a "Persistent notification". As seen in this screenshot below:
I have an application which I want to have a persistent notification for running my foreground service. But after all attempts, I don't get the the same observation as the LastPass app with saying its a "persistent notification". It just shows just as a "notification".
Does anyone know how to do this? Does anyone know if it really matters?
On my Android 10 device, I see that the LastPass app is able to create a "Persistent notification". As seen in this screenshot below:
That is not a "persistent" notification - that is a notification channel, which LastPass has apparently opted to call "Persistent notifications" for whatever reason.
I have an application which I want to have a persistent notification for running my foreground service.
Sounds like you want an ongoing notification.
Hope that helps!
Just make setOngoing true. It will be persistance.
NotificationCompat.
Builder(context, CHANNEL_ID)
.setOngoing(true)

How do some apps block/replace heads-up notifications?

Background
Ever since heads-up notifications appeared on Android, some people liked it for its quick handling, yet some hated it for showing on top of apps (especially games).
In order to show heads-up notifications, developers can use something like that:
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle("aa").setContentText("bb").setTicker("cc")
.setColor(0xffff0000).setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setPriority(Notification.PRIORITY_HIGH);
if (Build.VERSION.SDK_INT >= 21)
builder.setVibrate(new long[0]);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
Because of this, some apps came up with the idea to show ticker-text notifications that replace them somehow, just as it used to be before heads-up notifications:
https://play.google.com/store/apps/details?id=com.jamworks.noheadsup&hl=en
There are various scenarios where this could be useful. It could be, for example, useful in case of games, where full screen is used. That's because if the user is about to press the top area, and the heads-up notifications are shown, we would like to avoid accidental click on this notification.
The problem
Not only I can't find a way of how people did it, but it seems it doesn't work anymore on new versions of Android (tested on Android 7).
The only app I've found that blocks notification is this:
https://play.google.com/store/apps/details?id=com.aboutmycode.NotificationsOff&hl=en
yet it doesn't convert the heads-up notifications to "normal" ones. Instead, it just blocks them all. Plus it requires root, and seems to just change the settings of the notifications to "blocked" .
The question
Is it possible to temporarily block the heads up notifications (and yet convert them to ones without heads-up notifications ) ? If so, how?
Which restrictions does it have? Can it work without root? If it's possible with root, how? How does the "NotificationsOff" work?
Maybe this ability was possible before, but now it is not?
On Android 18+ there is a NotificationListenerService. This service gets notified when new notifications are shown. Then, I understand there are three ways to act:
Intercepting the notifications so they don't get displayed (not completely sure this can be done) Checked: if the NotificationListenerService doesn't call super.xxx when receiving a notification, the notification is also showed. So this method seems to not work.
Clearing notifications as they get posted. For this, you can use NotificationManager to either clear a given notification or clearAllNotifications Checked: it partially works to clear the notifications, but you still see the notification showing up and then it's not in the notification area (it's weird effect).
In API 21+ Lollipop it seems that you can override NotificationListenerService#getCurrentInterruptionFilter(). This method could return NotificationListenerService#INTERRUPTION_FILTER_NONE (or any other of the constants), (haven't tested, should be verified). Checked: NotificationListenerService#getCurrentInterruptionFilter() is final, so it cannot be overridden.
In API 23+ you can use both NotificationManager#setNotificationPolicy() and NotificationManager#setInterruptionFilter() (in that specific order) to control which notifications are shown to the user. Permissions are required for those APIs. Notice that this methods seem to be a convenience to be able to access the functionality, but skip implementing a complete NotificationListenerService. That's the only option that can work in a satisfying way
About NotificationListenerService, you can see the following samples in GitHub kpbird/NotificationListenerService-Example and in this post.
About NotificationManager, see additional information in this post in StackOverflow (specially interesting the highlighted comment) and in this post.
Example, tests and additional notes
I've uploaded the following repository to GitHub with an example based on kpbird's, to test all the assumptions and provide final conclusions.
Notice that the following steps to enable the permission for the app to be able to access the notifications must be followed in order for the app to function properly. This answer also provides a way to open System Settings in the correct section.
Also, for completeness, the following answer provides a way to check whether the permission is already granted or not.
Additional note: apparently first versions of Marshmallow have a bug where NotificationManager#setInterruptionFilter() doesn't work. See here and here.

Is it possible to create a Notification which doesn't generate Heads up Notification, but will appear in lock-screen

I am currently in a project which develops a DECT-based android system based on Android 5.0.1, and need to add a mode which will bring up the Dialer App while the InCallUi App is running (when there is an incoming call). When the Dialer App is in the foreground, there will be an annoying headsup notification from the InCallUi App showing the incoming call information displaying on the top of the screen.
I want to ask if there is a way to hide the headsup notification, while in locked-screen the notification entry can still be seen?
I have tried to change the priority of the notification, as indicated in the following link that the headsup notification only presented when the priority is set to HIGH, MAX and FULL_SCREEN: "If a notification's priority is flagged as High, Max, or full-screen, it gets a peeking notification.", but when I set the priority to LOW or MIN the headsup notification still shows:
https://material.google.com/patterns/notifications.html#notifications-behavior
Can anyone help? thanks:)
No, this was a security bridge on older versions of android that provided a way to services to run as ForegroundServices without the user knowing, that issue was fixed in android 4.4.
You can see this SO thread for more information.

how to disable system notifications in android using programming

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.

Android Wear: Programmatically stop my app's notifications from appearing on watch

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

Categories

Resources