Giter Club home page Giter Club logo

Comments (14)

jackrose3143 avatar jackrose3143 commented on August 20, 2024

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.

macdonst avatar macdonst commented on August 20, 2024

@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.

jackrose3143 avatar jackrose3143 commented on August 20, 2024

@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.

macdonst avatar macdonst commented on August 20, 2024

@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.

willoughby avatar willoughby commented on August 20, 2024

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.

macdonst avatar macdonst commented on August 20, 2024

@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.

JoseJPR avatar JoseJPR commented on August 20, 2024

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.

akreienbring avatar akreienbring commented on August 20, 2024

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.

cmartin81 avatar cmartin81 commented on August 20, 2024

I also have the same need as OP. But for IOS and Android. Please make a PR for this.

from phonegap-plugin-push.

ramyacl avatar ramyacl commented on August 20, 2024

how to call a function in ios when the app is in background

from phonegap-plugin-push.

macdonst avatar macdonst commented on August 20, 2024

This functionality has been implemented.

from phonegap-plugin-push.

varunreddy212 avatar varunreddy212 commented on August 20, 2024

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.

varunreddy212 avatar varunreddy212 commented on August 20, 2024

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.

lock avatar lock commented on August 20, 2024

This thread has been automatically locked.

from phonegap-plugin-push.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.