简体   繁体   English

在Android和Phonegap中推送通知

[英]Push notification in Android and Phonegap

I am searching for push notification in Android applications. 我正在Android应用程序中搜索推送通知。 I checked " Pushwoosh ": in the initPushwoosh method I saw GOOGLE_PROJECT_ID and PUSHWOOSH_APP_ID . 我检查了“ Pushwoosh ”:在initPushwoosh方法中,我看到了GOOGLE_PROJECT_IDPUSHWOOSH_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? 如何获得这两个ID? Or is there any better way to do this? 或者有更好的方法吗?

i saw Notification in PhoneGap documentation, Is it push notification? 我在PhoneGap文档中看到了Notification,它是推送通知吗?

Thank you. 谢谢。

These are the steps you must do: 这些是您必须执行的步骤:

  1. First you must register in Google APIs site, select Services: https://code.google.com/apis/console/ 首先,您必须在Google API网站注册,选择服务: https//code.google.com/apis/console/
  2. Turn the Google Cloud Messaging toggle to ON 将Google Cloud Messaging切换为开启
  3. In the Terms of Service page, accept the terms.Now you need to create the Server Key 在“服务条款”页面中,接受条款。现在需要创建服务器密钥
  4. Press “API Access” button 按“API访问”按钮
  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. 使用服务器密钥的优点是它允许您将IP地址列入白名单。
  6. Press “Create”. 按“创建”。
  7. You can find your GOOGLE_PROJECT_ID from the URL in your Google API console. 您可以在Google API控制台中的网址中找到您的GOOGLE_PROJECT_ID Usually it looks like this: https://code.google.com/apis/console/#project:12345678912:access In this example, it would be: 12345678912 通常看起来像这样: https : //code.google.com/apis/console/#project :12345678912:access在此示例中,它将是:12345678912
  8. Enter in Pushwoosh copanel: https://cp.pushwoosh.com/ 输入Pushwoosh copanel: https ://cp.pushwoosh.com/
  9. Create or enter in My Apps menu 创建或进入My Apps菜单
  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 当您进入应用程序时,您将在该页面或导航器的URL中看到应用程序代码,这将是您的PUSHWOOSH_APP_ID

Phonegap's Notification has nothing to do with push notification. Phonegap的通知与推送通知无关。 Check it here: http://docs.phonegap.com/en/2.2.0/cordova_notification_notification.md.html#Notification 请在此处查看: 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/ 要将Pushwoosh for Android与Phonegap集成,请查看手册: http ://www.pushwoosh.com/programming-push-notification/android-gcm-push-notifications-guide/

On this page are more guides for using Pushwoosh: 在此页面上,有更多使用Pushwoosh的指南:
http://www.pushwoosh.com/programming-push-notification/ http://www.pushwoosh.com/programming-push-notification/

Goodluck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM