Push notification in Android and Phonegap

女生的网名这么多〃 提交于 2019-12-06 12:13:24

问题


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


来源:https://stackoverflow.com/questions/13428272/push-notification-in-android-and-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!