sisi eshbien
sisi eshbien

Reputation: 13

check automatically for new message android

I am trying to create a simple android messaging app. So basically let us assume that user A sends a message to user B. I would like that user B receives a notification when the message is received. I know how to create the notification and all. But basically I would like to know how the user B constantly checks if a new message has been received even when he is out of the app, and then that would trigger the notification and subsequent actions.

Thank you

Upvotes: 1

Views: 3311

Answers (3)

Intsab Haider
Intsab Haider

Reputation: 3561

You can use Event Bus lib for this purpose. When new message will be received it will create and event and then you can receive that event event and do other operations.

Upvotes: 3

Raheel
Raheel

Reputation: 181

If you are talking about text messages then you will have to create a BroadcastReceiver http://developer.android.com/reference/android/content/BroadcastReceiver.html You can see my answer here for SMS Receiver Verify sms text message by app before it displayed to user Don't forget to give permissions in your app's manifest.

Hope it helps.

Upvotes: 1

MD1948
MD1948

Reputation: 292

You have to setup an unbound background service. With this you can constantly make pull-requests to your server or get push-notifications from your server and display notifications. https://developer.android.com/training/run-background-service/create-service.html

Upvotes: 5

Related Questions