Okay, so I know at first glance it seems like I'm stupid because I can just set the "click_action" parameter in the notification JSON from the server and have it open the activity with the matching intent filter. However, I don't want to do this, because as the documentation goes on to say "If set, [click_action] corresponds to category in APNS payload," and setting it makes the notifications not be delivered on my iOS app (because there is no corresponding category on the iOS app nor do I want to make one as that requires, I believe, adding in notification actions which I don't want to get involved in yet).
On iOS tapping the notification just opens the equivalent of the Android "android.intent.category.LAUNCHER" action. Bottom line, is there any way to replicate this in Android (or solve the iOS not displaying notifications if the "click_action" is set)?
In GCM intent class, on Message receive method just parse all the content and then simply start activity by putting inside intent, which activity you want to open on msg received.
I'd suggest using different payloads for Android and iOS clients. This would require your clients to identify their platform when they submit their InstanceID tokens, but once you know what platform the client is you can formulate the message more specific to the target platform.
Related
We want to send push notifications in Android and iOS to a group of users that match a certain condition. We can check if an user match this condition calling an API.
Our problem is that the users information changes very quickly and we don't have any way to keep track of this in our push notifications engine (OneSignal).
The only alternative we can think is to send the push notification to all users and client side call the API to get the latest user information. Depending on this we could choose to show the notification or ignore it.
Is this possible on Android and iOS?
It is 100% possible for sure. in the receiver class you call an intentservice, which can hit an api and get the latest information, based on the information you create notification using notification builder, and avoid if you dont want.
Yes, with the help of NotificationExtenderService this is possible.
Receive a notification in the background. Notification data is wrapped up in OSNotificationReceivedResult object. Now, read the notification id/title which should be unique for every notification.
Send this unique notification title/id along with user id to an API, which will return whether to show the notification to the user or not. If true then read notification title and message/description from OSNotificationReceivedResult and make a notification via NotificationCompat otherwise just ignore it.
Reference
I am using fcm push notification for my android app. I was able to display push notification on system tray when app is not launched. When I tap on the notification it opens the app launcher by default and I start an activity A from there. But the issue is, if I put the app to background and click on the app icon it again opens the app launcher rather than opening existing Activity A.
If the app process is killed, start the launcher activity. If the app is in the background, you can pass an intent to the notification which starts a DummyActivity that has no code on it, and immediatelly calls finish() on its onCreate() method. This will bring your app to the foreground.
Several things are not clear in your question. For example: How you send messages (from developer console or through rest api post requests to firebase backend)? What is your desired behaviour for app when push messages come? I will try to give you general answer that probably helps you to address issue and understand how to implement desired behaviour.
In any case, there are two types of Firebase push messages:
data messages
notification messages
more details about it check on Notification & data messages page
If you want to send additional details to activity that you are starting (something similar to bundle extras), you should use data messages and handle those in your service that extends FirebaseMessagingService by overriding onMessageReceived(RemoteMessage remoteMessage) method. This method is preferable for me because it is much more flexible. You can define all the details about showing notification based on received firebase message, including if notifications are bundled, what happens in details when user click notification and almost everything related to it.
If you don't need to start certain activity with some parameters, than you can use push messages and just define click_action. This method allows you to add define title, text and sound of notification (beside some other details) but it is not as flexible as if you send data messages
Here you can find detailed overview of possible parameters that you can use for different type of messages
Hope this helps
First of all, I have searched for a solution to my problem, but found none. Maybe it's too obvious or I am bad at searching. If it's so I am sorry.
Problem:
When sending GCM push notifications from server to mobile and supporting iOS, I must send a notification tag. This notification tag means the android system does not awake my application to handle the notification and does it itself. Even if I send data tag too.
My problem is when I try to make the app expandable. I know how to make it from code, but don't know how to set it from server side like the icon or color.
Question:
Is it any way to set notification as expandable (big view style) from server? If it's not, can I force the system to awaken my app to handle the notification?
With iOS there is a separate tag you need to have in your payload to so that you can get what you want on both platforms
if you look at the documentation you will see there is a tag content-available and when you use this tag it acts similar to how adding only the data tag in android would, you get the push in background vi the application:didReceiveRemoteNotification:fetchCompletionHandler: in your app delegate class.
There is where you would create the notification manually like you would on android
I want to implement push notifications on both Android and iOS with Google Cloud Messaging.
I don't want to use the notification key in my payload because the Android behavior is not ideal. On Android, I would prefer my receiver to always get triggered with the data payload, and I can construct the Notification myself using NotificationCompat. If you use the notification payload on Android, you have no control over the notification style, for example.
However, if I only send a data payload, I think my iOS app will not receive the push if it is backgrounded - killed, never launched since device restart, etc. I think there's that content_available flag for GCM which may trigger the push anyway?
Am I, on iOS, able to duplicate the Android behavior of always having my in-app code execute upon notification? I'd be fine constructing my own iOS notification based on the GCM data payload, and perhaps using something like a UILocalNotification, but from what I'm reading, iOS is requiring the notification payload to exist to make sure the push is always received by the user.
Can I get this kind of control on iOS?
You have to disable the content_available flag to false, so that it works on Ios as expected and provide full control on android,
Source:- I have worked on Push Notification on both android and IOS recently
From my research, it seems that you can't avoid using the notification payload. However, you can get rid of the default Android behavior of auto-creating a notification, if, instead of creating a MyGcmListenerService that extends GcmListenerService, you create your own GcmListenerService and extend plain old Service.
I am using Parse API in order to handle push notifications. In our Android application, I want to accomplish two things:
1) If we have received a Push Notification with the application is closed and the user clicks on the notification, I want to be able to understand that the application is being opened via a push notification.
2)If we receive a push notification while the application is open, I want to handle this and do some extra work.
In both cases, I want to be aware that the application has received a push notification in order to execute some special operations.
As far as I understand from Parse API documentations, it offers two methods of handling pushes: Responding with an Activity and Responding with an Intent. I am currently calling
PushService.setDefaultPushCallback(context, MainActivity.class);
in my Application class with needed changes in the AndroidManifest.xml file and already receive push notifications, this corresponds to Responding with an Activity method. But I don't know how to be aware of Push Notifications explicity with this method.
Thanks in advance.
When a push is received ,Check
1:Whether our application is in foreground or background.
If it is foreground, that means app is visible and do your stuff(show alerts or anything you want).
If app is in background,that means it is not visible and if you want to do any thing based on this.
i hope this helps..