-2

how to run app forever in background like whatsapp ?

I need when app is killed receive notifications.

I tried many way to this.But still not wrk.

I have no idea.

Kindly advice me,

Thanks

ANISUNDAR
  • 787
  • 5
  • 12
  • 28
  • I had a similar issue when working with Vivo Mobiles, later found out that there was a setting to allow apps to monitor notifications. So i believe it should be a setting with OS somewhere to allow your app receive notification even after killing it. – art-fan-vikram Jun 21 '17 at 06:16
  • Thanks for your reply.Can u pls help me.How i fix this issue. – ANISUNDAR Jun 21 '17 at 06:59

1 Answers1

0

how to run app forever in background like whatsapp?

App will be running forever in backgroung unless it is killed explicitly.

Even for Whatsapp if you kill it by pressing Force Stop button in Settings->Apps->Whatsapp, It can't receive any notifications unless you start it manually by opening the app. Also if the app is configured to Block all the notifications (in Settings->Apps->YourAPP->Notifications->Block all) then it won't receive any notifications.

I need when app is killed receive notifications.

Yes. The app can recieve notifications when it is in background(not forcefully stopped). In cordova I assume you are using phonegap-plugin-push for receiving notifications. The on.notification() event handler function will be called when notification is recieved.

Two cases when the app is running -

  1. Foreground - When app is in foreground, the notification is recieved and on.notification() event handler function will be called by default.
  2. Background - When the app is in background, Only notification is recieved. on.notification() event handler function will not be called by default. You need to set "content-available" : "1" in the data field while pushing notifications. And you cannot do this using Firebase Console. You need to have custom payload servers for pushing notifications.

Refer this answer for sending custom payload messages using PHP and NodeJS.

pro_cheats
  • 1,534
  • 1
  • 15
  • 25
  • Thanks for ur reply.I still dont understand.Can u pls explain.How to write background service for app in keep running forever – ANISUNDAR Jun 21 '17 at 07:51
  • you don't need to write a service for that. It will be by default running forever in background. For example check in `Settings->Apps`. So why do you want a service for that? – pro_cheats Jun 21 '17 at 07:57
  • Ya.I used phonegap - push plugin.I click hardware(end all) button.my app is closed.but the same time whatsup is not closed.how? – ANISUNDAR Jun 21 '17 at 08:02
  • what is hardware(end all) button? can you elaborate? Also please provide code samples in the question. It will be helpful to get better insight. – pro_cheats Jun 21 '17 at 08:04
  • i mean closed all app.i closed my app.i go to settings->App.My app is not running.at the same time closed my whatsup.and check settings->App.whatsup is running.also i restart my phone whatsup is run. – ANISUNDAR Jun 21 '17 at 08:07
  • Thanks for ur patient.I refer this link https://devdactic.com/ionic-2-push-notifications/ . Kindly pls advice me – ANISUNDAR Jun 21 '17 at 08:11