I implemented Push Notifications in Xamarin Forms 5 following this article: https://learn.microsoft.com/en-us/azure/developer/mobile-apps/notification-hubs-backend-service-xamarin-forms but when targeting Android 31 on Pixel 6a I get non silent (data) notifications but when I tap on them with my app on the background I get an error saying "indirect notification activity start (trampoline) blocked for X".
The only workaround I've found is unchecking this options on:
Developer Settings -> Don't pop notifications on screen -> Don't pop notifications on screen:
Is there a way to disable this in Xamarin Forms code for Android so I don't have to ask my users to enable developer options and uncheck this option?
I found this article that explains why this restriction was added for Android 12 but haven't found a way to disable this option programmatically: https://proandroiddev.com/notification-trampoline-restrictions-android12-7d2a8b15bbe2
Update 2/7/2023:
I read the article that #Guangyu Bai - MSFT shared and I tried sending Android test notifications from my Azure Notification Hub with the following payload:
{
"notification": {
"title": "Notification Hub Test Notification",
"body": "This is a sample notification delivered by Azure Notification Hubs.",
"android": {
"actions": [
{
"title": "test",
"pressAction": {
"id": "default",
"launchActivity": "com.mypackage.test.MainActivity"
}
}
]
},
"data": {
"property1": "value1",
"property2": 42
}
}
}
I also tried this:
{
"notification": {
"title": "Notification Hub Test Notification",
"body": "This is a sample notification delivered by Azure Notification Hubs.",
"data": {
"property1": "value1",
"property2": 42
},
"android": {
"pressAction": {
"launchActivity": "com.mypackage.test.MainActivity",
"id": "default"
}
}
}
}
In both cases I got the notification on my simulator but when I tapped on it, my app did not appear and got same trampoline error. Am I missing something in my test payload?
I see many articles online where they use Notifee from React using pressAction to solve this problem in Android: https://notifee.app/react-native/reference/notificationpressaction but I haven't found how that translates to Firebase Messaging Service structure.
You can check this link Indirect notification activity start (trampoline) from blocked for more information.
Update the app
If your app starts an activity from a service or broadcast receiver that acts as a notification trampoline, complete the following migration steps:
Create a PendingIntent object associated with the activity that the
user sees after clicking the notification.
During the construction of the notification, use the PendingIntent object that you created in the previous step.
To identify the source of the activity, for example, to perform logging, use extra when posting notifications. For centralized logging, use ActivityLifecycleCallbacks or the Jetpack Lifecycle Watcher.
Related
I'm using Capacitor for my App, I have an use case similar to whatsapp, when users receive a new message if your app is in background, you receive FCM notification in the notification tray, later if user open that particular chat directly by opening the app(without clicking on the notification), i'd like to clear that notification from the notification tray.
so here's what I thought
get active notification
find the active chat notifications by filtering extra data sent by FCM
clear those notifications programatically
however android's notificationManager.getActiveNotifications doesn't seem to provide access to FCM data.
below is the payload i'm posting to FCM(i want to use chatId and type in data section to clear active notifications).
{
"android": {
"priority": "high"
},
"notification": {
"title": "you have a new message from XYZ",
"body": "hello"
},
"data": {
"messageId": "62971793-0111-4c9b-bbb2-bb78262a0543",
"chatId": "631e162f5f286c23d13e06d5",
"type": "CHAT_NEW_MESSAGE"
},
"token": "fcmToken"
}
Here's the capacitor plugins Android Logic to get the delivered/active notification.
how can I achieve above use case?
I am trying to send notifications to both Android and iOS devices using FCM. The front end was coded with Flutter. I am working with Typescript/NestJS at the back end. For some reason, iOS devices receive all the notifications with a push notification/pop-up but Android devices sometimes don't. Strangely, the notifications ALL arrive at the test device INBOXES. It's just that sometimes, Android devices do not show a pop-up/push notification.
Targeting users thru a Firebase topic works as expected: push notifications do arrive for Android and iOS. I do have to find and filter out the users to target before sending the target device IDs to FCM. I am confident my filters are correct. The notifications arrive in the app inbox for both Android and iOS after my filtering. Also, changing the device ID/token in my database causes an error from FCM:
{"code":"messaging/registration-token-not-registered","message":"Requested entity was not found."}
If I revert the data to its original values, the app runs fine. I've checked and compared the data I pass to Node.js' FCM module and it looks fine. Here, messaging is an instance of firebaseAdmin.messaging().
param = {
"android": {
"data": {
"id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
"icon": "default",
"title": "Test",
"body": "Direct From Playground"
}
},
"apns": {
"payload": {
"aps": {
"id": "67bcd478-f643-4c9e-848a-be354a6b85d4",
"icon": "default",
"title": "Announcements",
"body": "Direct From Playground",
"alert": {
"title": "Announcements",
"body": "Direct From Playground"
}
}
}
}
}
messaging.sendMulticast({
tokens: value as string[],
...param,
});
Again, the code above sometimes successfully triggers push/pop-up notifications on Android devices but ALWAYS on iOS. Could this be a problem for the front-end handling of my data? Am I missing some parameters?
I'm trying to get push notifications running with React Native on iOS and Android.
To do so I am using firebase, as that seemed to be very convenient.
On Android I managed to show notifications when the app is in the foreground and at least show a log when the app is in the background, meaning I can process them.
On iOS I have not managed to do any of those, not from our custom backend in aws (via SNS), nor from firebase console with fcm token. What interestingly worked, was to show a badge on the ios app icon when sending broadcast messages to all users. So something seems to be received on the phone.
Now looking into this a little deeper I found that iOS needs notifications in the following format:
{
"Simulator Target Bundle": "com.compass.SomeExampleApp",
"aps": {
"badge": 0,
"alert": {
"title": "Push Notification Test",
"subtitle": "Hey! 👋",
"body": "Is this working?",
},
"sound":"default"
}
}
At least this is how you can test them on the sim.
1. Does it mean that I have to send the notifications in that same format? Or can it be something like:
{
"data":{},
"apns": {
"Simulator Target Bundle": "com.company.Example",
"aps": {
"alert": {
"body": "Wellcome to MyApp!",
"title": "MyApp"
}
}
}}
2. How can I send a format that iOS AND Android can read, show on screen and process in background if necessary?
Since we are sending only data messages I think this might be part of the issue, if I look at our backend.
Still when sending from firebase I am not able to show anything on screen on ios Device. Any hint?
I found a solution that actually works on both platforms although it is a bit weird since it seems to be outdated. Code needs to look like this to send to both iOS and Android:
{ "GCM": "{ \"notification\" : {\"content_available\" : true }, \"data\": { \"body\": \"Sample message for iOS endpoints\", \"title\":\"Hello world\"} }" }
As seen here APNS attributes seem to at least partly work if added within the GCM message like content_available in this case or badge.
im trying to send push by http to Huawei Devices with Huawei consolé integration, but the documentation is confuse, and i'm not really sure how to build my body to send
I have this, but only works for foreground, if the app is in background or terminated, the push isn't working
This is the portar i'm following https://developer.huawei.com/consumer/es/doc/development/quickApp-Guides/quickapp-access-push-kit#dataDesc
{
"validate_only": false,
"message": {
"data": "{title: Hello! 1, description: Hello, shirley!, params: { key1: test1, key2: test2}, ringtone: {vibration: true, breathLight: true}}",
"android": {
"title": "Hello! 1",
"body": "Hello, shirley!",
"params": {
"key1": "test1",
"key2": "test2"
},
"click_action": {
"type": 3
}
},
"token": [
"IAAAAACy0irbAADqfnlY9pfEgoWWoIzgCBXQzPol8CTNzV6i3V5byP7cIhuU74vovAwysjkI_XMwowYj1sv5SrhXRi-sYXB5OrplLHEB02LO0pKHcA"
]
}
}
The conditions received by the Push notification do not need to be run in the foreground.
According to the Docs,You can send push messages in either of the following ways:
Select target users in AppGallery Connect. In this case, messages can be pushed to both quick apps on the live network and those running on a quick app loader.
Send push messages to a large number of users in batches by invoking server APIs. In this case, messages can be pushed to both quick apps on the live network and those running on a quick app loader.
Conditions for a quick app to receive push messages are as follows.
I'm trying to send a payload using GCM that can be handled on the background or foreground by clients using Android and iOS. The messages are delivered to clients using both platforms that are subscribed in a topic.
Because I need the iOS app to handle the data even when the app is on the background or closed, I'm setting "content_available": true, which works as expected on iOS.
However, when I add that parameter, Android does not handle the received data and instead displays a blank notification.
Here's an example payload:
{
"to": "/topics/946",
"content_available": true,
"data": {
"time": "2016-02-04 18:33:08",
"message": "Hello",
"msgType": "chat",
"senderId": "50",
"senderName": "John"
}
}
The documentation says that data messages should wake the Android app anyway:
On iOS, use this field to represent content-available in the APNS
payload. When a notification or message is sent and this is set to
true, an inactive client app is awoken. On Android, data messages wake
the app by default. On Chrome, currently not supported.
What am I doing wrong?
EDIT: I've already tried using "priority":"high", which does not make any difference.