How to send notification when the app is closed? (android java) - java

Im making a reminder app that's based on location.
One of it's main features is to send the user a notification when he is close to one of the locations he set.
I've tried and searched the web, but still couldn't find a way to send a notification - when the app is closed (e.g. the user force closed it (not force stopped!)).
I've come across the idea of foreground service - which isn't bad, but has one problem - it HAS to send a notification when it is started.
I want the notifications to be like most apps' notification - for example, instagram just sends a notification that a message has been received. There's no notification saying that a service has started.
If someone knows a way - please, tell me. I'm lost :)
Im sorry for not including code. Everything i've tried so far isn't relevant - I need ideas.

Related

Receiving message from server instantly while android screen is locked/is in a sleep

I want to write a 'service' app that will be connected to a server, the server will send messages to the app and the phone will popup a notification to the screen instantly upon receiving the message from the server even if the phone is locked. (like Whatsapp/Telegram etc..)
Push Notifications are not instant enough.
I was thinking about using WebSocket for that, but not sure it is the best approach.
What is the best approach?
Sample code will be appriciated!
Thanks.

Allow Notifications To Be Sent When App is Closed Or Not Running

I am developing an app that allows users to receive notifications from two places: 1) from a calendar event notification and 2) from an alarm/reminder notification. The notifications work when I have the app open but I want them to work when the user has the app closed or not currently running. Is there a way to do this? Please let me know if I need to send any code!

Notification in Android Studio y Firebase Database when the app is closed [duplicate]

I am creating an Ionic 2 app with firebase and I need a way to listen to database changes (specifically on child_added) when the app is closed (I.e. in foreground,background and killed)
Basically, I want to use WebRTC to make calls within the app like whatsapp and I am following this post - https://websitebeaver.com/insanely-simple-webrtc-video-chat-using-firebase-with-codepen-demo
However, the only thing that puzzles me is how it will work when the app is closed. Can anyone please help me understand?
Thanks!
It's not possible to actively listen to database changes using the Firebase client SDK in exactly the same way that you can when your app's code is running.
If you want your app to receive information about changes to your database, you can instead use Firebase Cloud Messaging to send your app a notification with a small payload that contains information about the change. When your app receives the notification, it can then make a decision about what to do. There are some limitations with web support, so be sure to read about that.
Also look into Cloud Functions for Firebase to make it easier to write some server side code that can trigger in response to a database change and send a notification when those changes happen.

Save chat messages with closed app

Good evening!
I'm developing a chat application that looks like WhatsApp. I need the received messages to be saved on the user's mobile device. Until then everything was ok, because I was saving the messages when the user received the push notification on the mobile, but the problem happens when the application is closed because when the application is closed the push notification does not trigger the received push event (I am using the Onesignal to send the push).
I'd like to know how I can do this, ie get a notification and process it even with my closed application. I think it has to do this because Whatsapp does this and also Spotify also does it when I connect the Spotify to another device it automatically forces the opening of the application on my cell phone.
So my question is, how do I handle an event with the application closed or even force it to open according to a particular event?
I'm using the technology of Ionic 1 and Angular.js. For push notification I am using the OneSignal provider.
Thanks in advance for your attention and hope someone can help me. Thank you!
I'm fairly sure you won't be able to do what you're describing. There is a 'background push' feature introduced in iOS 9 that lets an app receive a payload triggered via push even when it is closed, but that's more for downloading (for example) a new edition of an online magazine, rather than lots of messages.
The difference betwen those two use cases is that if you're subscribed to a magazine, you might want the latest issue to download automatically whilst you have an internet connection, so that you have the issue to read when you're flying/on the train or whatever. A chat app... is pretty useless if you're not connected to the internet anyway, so there's no urgent need to have new messages 'pre-downloaded'
Even if you could do it, I don't think it would be best practice as there's too many scenarios where people won't have internet anyway so you're going to be left without the full message history when a user opens the app (not to mention push notification delivery is not tracked or guaranteed), so you're going to have to do some sort of query when the app launches to download new messages anyway.
If you've got code already that checks and downloads new messages while the app is open, that's great. But if its closed, you'll just need to run some sort of query on launch to download unread messages or something like that

Disable Google Calendar Push Notification when app is an owner of the change

When I create/update a Google Event from my app using java client:
events
.insert(originalCalendarId, googleEvent)
.setSupportsAttachments(true)
.execute()
I'm still getting push-notifications about event creation/update.
I don't want to get them since I'm the one who did these changes. The changes are applied on the app in a different way and additional push notifications are useless in this case.
However, I need to get new changes when they are made somewhere else(another app or Google Web UI).
Is there a way to handle this case? Maybe there is an approach to make Google know that push-notifications for specific queries aren't needed.
I also see that there is a property:
com.google.api.services.calendar.Calendar.Events.Insert#sendNotifications
But, no matter what I set here, notifications are still sent.
I think you have subscribed for a resource and you expect do not receive push notifications if your application have just done some changes. So you should use:
.insert(originalCalendarId, googleEvent)
.setSupportsAttachments(true)
.setSendNotifications(false)
.execute()
If you receive any way push notifications please check in your push notification X-Goog-Channel-ID with your own to be sure that is Google issue. I believe you have some old subscriptions that was not handled correctly and this is reason why do you receive the changes over push notifications.

Categories