Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Question: What exactly does this plugin allow me to run in the background? #3

Open
LuisMCunha opened this issue Dec 2, 2015 · 20 comments

Comments

@LuisMCunha
Copy link

I'm able to send and schedule notifications, but I'm unable to do simple web requests or logic in javascript when I press the back button on android.
So what exactly does this plugin allow, just notifications and alarms, or am I just doing something wrong?
Thanks.

@agrieve
Copy link
Member

agrieve commented Dec 2, 2015

It's mainly for notifications / alarms and the like.

If you just need to be able to stay alive when the back button is pressed, I think you can listen for the "back" event and wire it up to "navigator.app.hide()" so that the app is just backgrounded rather than killed (which is the default-but-a-bit-quirky behaviour for all android apps)

@LuisMCunha
Copy link
Author

I'm getting error Uncaught TypeError: navigator.app.hide is not a function when calling navigator.app.hide(), also I couldn't find any reference to it on the web. Am I missing something?
Thanks.

@mburger81
Copy link

Hi @agrieve & @MoPHL
Can you help me on using this plugin? I see there is no really community for this plugin. And I don't know where to get help.

I'm trying to integrate this plugin in ionic2, but bevore there are some other questions.

Is this plugin like a android service? So can this run in background with closed APP and do something, like pulling a service?

@LuisMCunha
Copy link
Author

LuisMCunha commented Aug 16, 2016

Hi @mburger81 I have not used this plugin with ionic 2, so I cannot confirm it's fully compatible.
With regards to your question, this plugin allows for continued background task execution, but not like a service, it simulates continuous audio playback to keep the application alive in the background and allow you still execute code.
Hope this helps.

@mburger81
Copy link

Hi @MoPHL, thx for your answer.
I need something like local push notifications without cloud, only from server to mobile.
We are build a SmartHome application and there should be a notification on smartphone without need a external cloud push notification server.

So I need something like a Android Service, which is always alive, also on reboot, which has an websocket connection to server.
Some ideas?

@LuisMCunha
Copy link
Author

@mburger81 unfortunately there are limitations to when you can run javascript code during some lifecyle phases of the application. There are some comercial solutions for push notifications on hybrid apps (ionic push, etc.), but I have only implemented one myself as a part of a native app.
If a comercial solution does not fit your needs, you could easily write a service for your application using native code that then calls the webview whenever an event is received. Shouldn't be more than a few lines of code.

@mburger81
Copy link

@MoPHL okay, I know the commercial solutions for push notifications, but for those services server and also mobile phone must be ONLINE, something we can not to guarantee. So we need a OFFLINE solutions, direct connection from server to mobile phone, our server is a WLAN ROUTER, so the phone connects to this router which sends notification to phone. But the problem is, what if the app is not open? For that we need a background service.

You wrote, "I have only implemented one myself as a part of a native app", to you intend you implement a push notification server as GCM or ANPS or ionic push? Or you intend you did something own?

You also wrote "you could easily write a service", do you intend with this cordova-plugin?? Like this example?

https://github.com/MobileChromeApps/cordova-plugin-background-app/tree/master/example-app

@LuisMCunha
Copy link
Author

@mburger81 I don't understand what you mean by "we need a OFFLINE solutions", you cannot receive push notifications without network access, even if it is just a local network.
I implemented a custom push notification service that connected to a socket on a remote server, you could add such functionality to your app in a cordova plugin like fashion, you just need to open the correct page on the webview when the user taps on the notification.

@mburger81
Copy link

@MoPHL, okay sorry, with OFFLINE I intend no INTERNET so no access to some push notification server as GCM in the CLOUD.
For sure I need a connection from PHONE to SERVER, as described the phone/tablet is connected to the WLAN ROUTER which is our JAVA OSGI SERVER :)

I need the same thing as you described, "custom push notification service that connected to a socket on a remote server".
Cordova plugin like fashion? Sorry we are new on cordova, but we can not find a "plugin like fashion". Can you share more infos?
It will be great! :)

@LuisMCunha
Copy link
Author

LuisMCunha commented Aug 16, 2016

@mburger81 What I meant is that you would have to implement the android service natively, cordova plugins are basically native code that talk to the nativeview. You could implement the service that deals with the push notifications natively and just have it call the webview whenever the user taps on a notification.

@mburger81
Copy link

Ok, I understand that. My hope was, do you have perhaps some code to share, if you already have done something like that?
cordova-plugin-background-app works also only on android, so I'm also not sure if there is a way to do it on ios

@LuisMCunha
Copy link
Author

@mburger81 I do not have any code that would work for your situation as I have only done it in fully native applications.
My suggestion for you would be to implement an android service in Java that listens to a socket and whenever an event is triggered send a local notification to the user, and the onClick() method of that notification would send the user to the appropriate page on the webview.
On iOS it will be trickier as apple imposes several restrictions on background tasks, so I recommend you read up on their documentation.

@mburger81
Copy link

@MoPHL The thing is, iOS has very restrictions on background tasks. so probably there is absolutly no way to do it as we need. Probably we need always a cloud message system.
I hoped there is a solution for me, but I don't think so :|

@LuisMCunha
Copy link
Author

@mburger81 do some research on how applications like google hangouts solve this issue, maybe it is possible to do the same thing they do.

@mburger81
Copy link

mburger81 commented Aug 17, 2016

@MoPHL, google hangouts, telegram, what's app and other programs all use cloud messaging or not?
what's app for sure

@LuisMCunha
Copy link
Author

@mburger81 I have no idea what they use, but they have push notifications, so check how they do it and if it is possible for you to do the same.

@srsarcasmo
Copy link

saludos, disculpen yo estoy usando una apliucacion de ubicaciones, sera capaz de usar javascript de fondo ? y trabajar con ajax

@MehdiAroui
Copy link

take a look here https://github.com/Red-Folder/bgs-core/wiki/Build-your-own-Background-Service that may help

@mburger81
Copy link

mburger81 commented May 1, 2017

@mehdiar your last link doesn't exists anymore! Can you share the new one?

EDIT: the url is linked wrong on clicking on it, but open the url on by copy paste TEXT it does work!!
thx

@paredesivan
Copy link

@MoPHL i nedd only that the app run on reboot on background to listen push notifications. and when i run the app manually, i wish that run in foreground. this plugin works??

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants