Save chat messages with closed app - java

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

Related

How to send notification when the app is closed? (android 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.

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.

Android - Disable text message notifications programmatically

I'm working on an application that handles text messages. This is a personal application and I do not plan to release it, however it's basically going to allow me to share my text messages (and phone number) between numerous devices through the internet. It's a fun learning project too as a first application, and I've done quite a lot.
However the annoying part is the text-message popup that my device gets when receiving a message. I love it when I'm using the device, and I could always just go into the options and disable the popup when I'm not planning on using the device, but I'm a very, very forgetful person and turning it back on wont always happen. Then I'll never reply to messages.
Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message, however I still want it to be logged in my messaging history. So the message can't just be "discarded". This should only happen of-course while my applications service is running.
I've been searching through the android API for quite some time and I just can't seem to figure this out, is it possible and if so can you link me to the proper place in the API to begin?
Basically I want to programmatically interrupt (or not even notify) my default messaging application of the text message...
This isn't possible.
Assuming by "interrupt" you mean to prevent the default SMS app from issuing its Notification, you can no more do this with the default app than you could with any other app that you don't control.
Additionally, as the default SMS app responds to the SMS_DELIVER_ACTION broadcast, and it is the only app to receive this broadcast, it wouldn't be possible to "not...notify" the default app of an incoming message. Your app wouldn't even have a chance to abort the broadcast, even if it were possible to do so.
(In versions prior to KitKat, it was oftentimes possible to register a Receiver with a high priority for the SMS_RECEIVED_ACTION broadcast, and then abort the broadcast before the native SMS app received it. This is what rajan ks's answer refers to.)
...however I still want it to be logged in my messaging history.
The default SMS app is responsible for writing all incoming messages to the Provider. Even if you were able to prevent the default app from receiving the incoming message, your app would then have to write the message itself. This isn't really possible, either, as the default app is the only one with standard write access to the Provider.

Android Widget like WhatsApp to check connectivity and send data

I have a running Android app, which sends data to a server. If the device is not connected to the internet, it should be possible to save the data temporarily on the device. If the device retrieves the connection, it should send the saved data to the server. Even if the app is closed.
My question is, how to create a "listener" which listens on the internet connection? This mechanic should work like WhatsApp. In WhatsApp you can receive messages, even when the app is closed.
I've looked a bit around....could this be a Widget? And if it is one, how to not display it on the Home screen? I don't need to display any information there.
You can register for changes to connectivity by following the instructions at Monitor for Changes in Connectivity. When you hear that the phone has connectivity, send your data.
Sorry, I don't know enough about widgets to advise whether they'd be a good fit here.

Sending notification to everyone running an application, Android

Set up:
I have a system which has multiple users. Each user will download my app onto their Android phone and use it. What I want is when any user performs a specific action (I have two in my app), I want to pop up a notification in all the other user phones.
A simple break down is like this:
Start app --> Navigate to the part where action is performed --> Perform the action --> Store the action the a DB --> Notify ALL USERS --> Pop up the same notification on all phones.
How would I go about this problem? Can anyone suggest ideas or links, cause I don't even have a clue on how to approach this.
If you are looking to send notification to all users, even if all the users are not actively using the application, then Puch Notification is a good approach.
Push notifications let your application notify a user of new messages
or events even when the user is not actively using your application.
On Android devices, when a device receives a push notification, your
application's icon and a message appear in the status bar. When the
user taps the notification, they are sent to your application.
Notifications can be broadcast to all users, such as for a marketing
campaign, or sent to just a subset of users, to give personalized
information.
Have a look at Android Google Cloud Messaging
Also I have found XMPP a good solution as described by this post.
You will find some good solutions here and here
Well, you will need a database on a server, and then you will need the app to constantly (or at intervals) query the database in the background for changes, and notify the user when it finds one. A system similar to how many apps give notifications is what I am getting at.

Categories