ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

How to launch my ionic app when a received push notification is clicked? #210

Closed bmwertman closed 8 years ago

bmwertman commented 8 years ago

I'm using node-gcm to send scheduled push notification to my ionic/cordova application from my app's server. I've been able to launch the application from a url using Eddy Verbruggen's Custom-URL-scheme PhoneGap plugin.

I tried to set the URL generated by this plugin to the click_action in order to launch the app without success. Is this feasible? I can't write an intent-filter directly in my AndroidManifest.xml without it being overwritten when Cordova builds my app.

hypesystem commented 8 years ago

What is "the URL generated by this plugin" that you mention? I am not sure I understand what you have tried to make this work :-) Could you elaborate?

bmwertman commented 8 years ago

I was probably incorrect to say that the plugin generates the URL. It sets a 'URL_SCHEME' in an intent-filter as shown here. When I try to call the intent-filter created by the plugin by name I get this;

This is the intent-filter generated by the plugin; <intent-filter> <data android:scheme="MY_URL_SCHEME_NAME" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter>

This is the click action referencing the intent-filter by name; notification: { title: "You have a new task", icon: "ic_stat_wrench_head", color: "#387ef5", sound: 'beep.wav', body: task.description, click_action: "android.intent.action.VIEW" }

The notification is received on my device but when I click it I get this;

browser_screenshot

chrisgriffith commented 8 years ago

See if anything in this recent workshop might solve your issue. It was the recent PhoneGap Day conference. I did not attend this workshop, but thought it might help.

http://macdonst.github.io/push-workshop/

On Fri, Feb 5, 2016 at 6:51 AM, Brad Wertman notifications@github.com wrote:

I was probably incorrect to say that the plugin generates the URL. It sets a 'URL_SCHEME' in an intent-filter as shown here https://github.com/EddyVerbruggen/Custom-URL-scheme#android. When I try to call the intent-filter created by the plugin by name I get this;

This is the intent-filter generated by the plugin;

This is the click action referencing the intent-filter by name; notification: { title: "You have a new task", icon: "ic_stat_wrench_head", color: "#387ef5", sound: 'beep.wav', body: task.description, click_action: "android.intent.action.VIEW" }

The notification is received on my device but when I click it I get this;

[image: browser_screenshot] https://cloud.githubusercontent.com/assets/2573903/12849504/ee9980ec-cbed-11e5-9b00-2c960e2f3a3b.png

— Reply to this email directly or view it on GitHub https://github.com/ToothlessGear/node-gcm/issues/210#issuecomment-180387556 .

bmwertman commented 8 years ago

@chrisgriffith thanks. That helped. I'm able to get my app to display the action buttons following module 6 of that tutorial. But they only display if the app is open or in the background. If the app is closed they don't get appended and selecting the notification does nothing.

eladnava commented 8 years ago

@bmwertman Welcome to node-gcm! I think this question is outside the scope of the project, though, since it's a matter of interfacing with Ionic to handle the notification intent correctly, and the push does make it to the device successfully.

Also, since it's not really an issue, but a question, I'd suggest asking on StackOverflow instead.

ronycohen commented 8 years ago

Hello @bmwertman do you know how to open a specific state from a node-gcm notification. I installed phonegap-plugin-push on my ionic app.

bmwertman commented 8 years ago

@ronyrun I'm still working on that. I went through the setup instructions for IonicPush to get my client side setup and used node-gcm on the server side.

ronycohen commented 8 years ago

@bmwertman I didn't the IonicPush plugin, I use the phonegap-plugin-push instead

ronycohen commented 8 years ago
var push = PushNotification.init({ "android": {"senderID": "721393051486"},
         "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } );

    push.on('registration', function(data) {
        // data.registrationId
    });

    push.on('notification', function(data) {
        // data.message,
        // data.title,
        // data.count,
        // data.sound,
        // data.image,
        // data.additionalData
    });

    push.on('error', function(e) {
        // e.message
    });