Comments (14)
I found a solution by modifying java code:
Modify GCMIntentService.java onMessage method
From:
if (PushPlugin.isInForeground()) {
extras.putBoolean("foreground", true);
PushPlugin.sendExtras(extras);
}
else {
extras.putBoolean("foreground", false);
// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
To:
if (PushPlugin.isInForeground()) {
extras.putBoolean("foreground", true);
PushPlugin.sendExtras(extras);
}
else {
extras.putBoolean("foreground", true);
PushPlugin.sendExtras(extras);
// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
What I have done is:
- Set foreground variable true even if app is in background.
- Call PushPlugin class's sendExtra method to invoke JavaScript on Message event.
If anybody has better solution without modifying java code, please let me know.
& also please let me know what code to change in iOS to make it work like this.
Thanks
from phonegap-plugin-push.
@jackrose3143 no, you will definitely need to modify the Java code to send the notification when the app is in the background. Feel free to open a pull request on this but I'd like to see this an option you can pass into the init function so that users can control the behaviour. Also, you'd need to do some special checking just in case the app wasn't running at all.
from phonegap-plugin-push.
@macdonst Thanks for the reply.
Adding an option to control this behavior is a nice idea. I'll make a pull request around this weekend, after implementing option.
Yes it works when app is in background, but it is not working when app is not running at all.
from phonegap-plugin-push.
@jackrose3143 yeah, it'll never work when the app is not running. There is no activity class for the service to communicate with.
from phonegap-plugin-push.
Could you pass the push params as part of the query string when the app is loaded from a cold start? I have the requirement where I want to redirect the user to the appropriate page which is based on the data in the push. This works find when the app is in the background.
from phonegap-plugin-push.
@willoughby so what you are saying is that you are not getting the push information when loaded from a coldstart on Android if you start the app by clicking on the notification in the shade?
from phonegap-plugin-push.
Hello everyone,
My problem is similar.
If I click on the top notification bar iOS or Android, Yes run the function "push.on('notification', function(data) {}", but if I click on the app´s icon not run the that function.
Someone can help me?
from phonegap-plugin-push.
Hello, I just implemented the code of the OP. Indeed it is a very usefull feature, as I have the same needs as the OP.
@jackrose3143: I'll encourage you to create a pull request for this.
from phonegap-plugin-push.
I also have the same need as OP. But for IOS and Android. Please make a PR for this.
from phonegap-plugin-push.
how to call a function in ios when the app is in background
from phonegap-plugin-push.
This functionality has been implemented.
from phonegap-plugin-push.
Hi I am using content- available to get js to run when the app is running in the background but it isn't working. I tried the code modifications discussed here as well in the else block of v1.4.3 but js isn't running till after the app comes into the foreground.
I am running Android Marshmallow.
Thanks
Varun
from phonegap-plugin-push.
Hi I am now using v1.5.3 of the plugin but I'm facing the same issue.
I am using "content-available":" 1" in data
Is there something that I am missing?
Any help would be appreciated
Thanks
from phonegap-plugin-push.
This thread has been automatically locked.
from phonegap-plugin-push.
Related Issues (20)
- Callbacks (hasPermission, register) are not called on iOs 13 HOT 3
- @parmarkaushik15 yeah, like I said in my last comment, if the app is forced closed there is no web view in memory to run the JS. The best you can do at this point is look into using the force start parameter. HOT 1
- ios: notification event not firing after app is closed when user opens app directly - works on android HOT 1
- On notification event not firing when cordova local notification plugin is installed. HOT 5
- IOS. Does not show 'Allow / Deny' notification dialog and not receiving push notification
- Blank screen is displayed in few devices instead of picture
- iOS13 APNS Device Token HOT 2
- getNotificationSettingsWithCompletionHandler - completion handler never executes on iOS 9.3.5
- Incompatibilty phonegap-plugin-push whit cordova-plugin-googlemaps HOT 5
- Unable to send push to browser(Firefox, Chrome) using fcm/gcm getting 'InvalidRegistration'
- On Android it receives notifications but they don't appear on Firebase Analytics
- Not every key in the firebase's {android/ios}.notification object is supported in "additionalData" object
- Unable to compile 2.3.0
- HELP - Failed to install 'phonegap-plugin-push': undefined - cocoapods -macOs Catalina HOT 1
- registration is not called
- iOS: Can't process background notification on low battery
- Security Error with android:exported=true
- [Android] on('notification') 'coldstart' value is acting wacky and not as documented (works only on iOS)
- Sporadic registrations on iOS using Xcode
- FCM version is not up-to-date.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phonegap-plugin-push.