Open android app when clicking in an Azure Reach push notification - android

I'm trying to open an Android app when clicking in an Azure reach push. System and In-app notifications are arriving to devices correctly but when I click it nothing happens.
I've followed this documentation https://azure.microsoft.com/en-us/documentation/articles/mobile-engagement-android-integrate-engagement-reach/ and after some research I've noticed that my EngagementReachDataPushReceiver extended class (with the overriden methods "onDataPushStringREcieved" and "onDataPushBase64Received") never get called.
Of course I've added the reference in the Android manifest to that class so... Someone have any clue about what can be happening?

this question is already taken care of on the official MSDN forum, I see you also posted there: https://social.msdn.microsoft.com/Forums/en-US/8bc993cf-66a5-47d9-8778-528661913417/my-engagementreachdatapushreceiver-extended-class-doesnt-get-called?forum=azuremobileengagement

Well, finally I've found the solution on my own. The problem was in the onNotificationPrepared overriden method, specifically the way I was building the notification:
Notification.Builder builder = new Notification.Builder(mContext)
The notification builder needs to be:
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(mContext)
(from android.support.v7.app)
And magically the received pushes started to open the app again.

Related

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

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.

Message center in Android

The Android app I'm developing interacts with a remote machine that may returns errors or have problems.
Currently I'm showing ugly popups at every warning or blocking error, but I wanted some sort of centralized notification center. I don't want to use normal Android notifications since the user has to leave the application.
I wanted some sort of badge indicating the number or warnings/errors that have happened until now and something that can resume what happened (like a listview with all the errors happened).
I'm wondering if that's the best approach to deal with this type of problem and/or if there are any public library out there that might solve my problem.
I've seen that Snackbar might be helpful for non blocking errors, and there are a lot of badge libraries, but still nothing for the "notification center".
If you are intending to "notify" users about progress, issues and other important messages. The logical place to do so would be using a Notification. You can also provide buttons in the notification that directs the user to conflict resolution.
Documentation about Notifications.
Official Documentation for creating Notifications.
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
Make sure that you are certain that your user actually cares about these messages (errors). Provide them a way to ignore them. Usually in the App settings.

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.

How to handle NotificationBar in android

I tried the code form the answer of this question: How to put media controller button on notification bar?
By calling the
showNotification()
method my app gets closed. How to prevent this? And how can i handle that this method is just called if the mobile phone api is >= 16. Because i think it is just available since api 16.
I've read, that there is a solution for lower API:
import android.support.v4.app.NotificationCompat;
But i didn't got it working, so i just wanted to prevent calling it.
And can i delete the notification from the bar, by onDestroy() of my app?
The code on that page is for the most difficult case using RemoteViews, and it looks dubious anyway. (E.g. it creates a subclass of Notification with a constructor that creates another Notification.)
The normal approach is to use a NotificationCompat.Builder to build your notification, and NotificationManager or NotificationManagerCompat to show and cancel it. See the Notifications API Guide for details and example code.
Also see the Notifying the User documentation and the Notifications design guide.
Generally, your app should only show a notification when its activity is not visible. When the user taps on the notification, it should usually open the activity which should in turn cancel the notification.

Creating Wearable notifications without the builder?

Is it possible to create wearable notifications without using the notification builder?
I already create a notification via new Notification on newer devices and would like to keep that code and still add the Wearable notification to my existing one. Is this possible, or is everything connected to the builder helper class for now?
It seems that there is no WearableNotifications.Builder class anymore in the newest SDK.
But you need to do nothing to simply let your Notification show on Android Wear Devices.
If you want to have a slightly better look for your Notifications you can use WearableExtender to add Android Wear specific actions, pages and layout options.
The WearableNotifications.Builder class is only needed if you want to add 'wearable extensions' to your notification. The normal notifications shown by your app are displayed also on the wearable connected to your device without any further integration work.

Categories

Resources