Push notification in Android and Phonegap

2019-04-14 03:19发布

问题:

I am searching for push notification in Android applications. I checked "Pushwoosh": in the initPushwoosh method I saw GOOGLE_PROJECT_ID and PUSHWOOSH_APP_ID.

function initPushwoosh() {
  var pushNotification = window.plugins.pushNotification;
  pushNotification.registerDevice(
    {
      projectid: "GOOGLE_PROJECT_ID",
      appid : "PUSHWOOSH_APP_ID"
    },
    function(status) {
      var pushToken = status;
      console.warn('push token: ' + pushToken);
    },
    function(status) {
      console.warn(JSON.stringify(['failed to register ', status]));
    }
  );
  document.addEventListener('push-notification', function(event) {
    var title = event.notification.title;
    var userData = event.notification.userdata;
    if(typeof(userData) != "undefined") {
      console.warn('user data: ' + JSON.stringify(userData));
    }
    navigator.notification.alert(title);
  });
}

How can I get these two IDs? Or is there any better way to do this?

i saw Notification in PhoneGap documentation, Is it push notification?

Thank you.

回答1:

Phonegap's Notification has nothing to do with push notification. Check it here: http://docs.phonegap.com/en/2.2.0/cordova_notification_notification.md.html#Notification

To integrate Pushwoosh for Android with Phonegap check the manual: http://www.pushwoosh.com/programming-push-notification/android-gcm-push-notifications-guide/

On this page are more guides for using Pushwoosh:
http://www.pushwoosh.com/programming-push-notification/

Goodluck!



回答2:

These are the steps you must do:

  1. First you must register in Google APIs site, select Services: https://code.google.com/apis/console/
  2. Turn the Google Cloud Messaging toggle to ON
  3. In the Terms of Service page, accept the terms.Now you need to create the Server Key
  4. Press “API Access” button
  5. Press “Create new Server key”. Either a server key or a browser key should work. The advantage to using a server key is that it allows you to whitelist IP addresses.
  6. Press “Create”.
  7. You can find your GOOGLE_PROJECT_ID from the URL in your Google API console. Usually it looks like this: https://code.google.com/apis/console/#project:12345678912:access In this example, it would be: 12345678912
  8. Enter in Pushwoosh copanel: https://cp.pushwoosh.com/
  9. Create or enter in My Apps menu
  10. When you enter into an app you'll see the Application code in that page or in the navigator's url and this will be your PUSHWOOSH_APP_ID