Intercept push notification from showing in app - android

I need to have a toggle for push notifications in my app, but I can't make changes in server. Can I intercept the push message in GCM and not show it in the topbar?

Since you are the one displaying the notifications, you do not have to "intercept" anything. You are already receiving the GCM messages, with the code that you wrote, where your code is displaying the Notification. Simply have that code examine your SharedPreferences (or wherever the "toggle" is stored) to see if the code should actually display the Notification.

Related

Is there any alternative to notification notify device but without sending native notification?

Example: I have mobileDevice1 / mobileDevice2 / laptop
Goal: I need to notify mobileDevice1 with some message by sending it from mobileDevice2 and laptop. The message need to passively appears (listens) on mobileDevice1 without any interaction like pressing update button. But the thing here it must be not a regular push notification because this message must not appear in the mobileDevice1 notifications list. It can appear in some view for example regular recyclerView but not in native device notifications list
Is there a way to do that way?
It sounds like you want to send a data-only message, which is always delivered to the onMessageReceived method in your application code and never displayed by the system.

Handling fcm notification when app not launched

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

Mass push notification sending in some intervals

I am trying to figure out how Facebook / Twitter sends push notifications like "You have 20 new followers"I don't know how to call it but i want to learn the underlying algorithm of this in Android. Please help, Thanks !
On Android you can execute your code before actually showing a push notification. They could simply send a push notification to all devices with an identifier, then the app can make a request to the server and get the needed information in order to show the push notification.
They can also send one push notification per device, as they can associate the push notification key with the user login, and the server would fire a push notification every time there is an event that demands a push notification.
But there are also other ways of doing this, for example, they can, for example run locally in background and create a local notification when the app decides it is necessary.

Can we perform an ACTION programmatically on a Notification from Notification Listener Service?

Is it possible to invoke an ACTION programatically on a Notification from a NotificationListenerService?
I have written a Notification Listener service that reads out all the incoming notifications and dismisses when done. But I'm not sure if we can perform any ACTIONs on the incoming notifications.
For eg: On a WhatsApp message notification I can read the package name, sender and message details but is there a way to send a reply back to the sender?
Currently Android Wear is doing this so I'm wondering if it is following a generic approach of acting upon a Notification or it has a specific API to WhatsApp service.
When ever a whatsapp notification is received via notification listerner service there is one another notification thats received (hidden) which has a tag value something like this XXXXXXX#s.whatsapp.net (xxxxxxx being the phonenumber), I think this somehow holds the key to sending a reply to this user.
I am working on other app logic, which does not require you to send back replies but I found this interesting but could not get enough time to check it myself.
Yes, you can do it by this function:
sbn.notification.actions[0].actionIntent.send()
Yes, we can perform actions on notifications. Pushbullet app on Android has an ability to reply to WhatsApp, Hangouts, Facebook messenger etc when user enters the message form desktop which means that there is a way. I am still trying to figure out how to do it.

Handling Parse Push Notifications in Android

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..

Categories

Resources