问题描述
我正在使用 php、jquery 和 phonegap 创建一个 android 应用程序.我在谷歌搜索了很多东西,但我找不到发送推送通知.我见过这个 Phonegap and Parse.com Push Notifications IOS 但我我不清楚我可以获取 deviceToken.
I am creating an android app using php,jquery and phonegap. I have searched so many things in google but i cant find to send push notification. I have seen this Phonegap and Parse.com Push Notifications IOS But i am not clear ho can i get deviceToken.
我也看过下面的
https://parse.com/questions/php-rest-example-of-targeted-push
我了解如何发送通知.但是没有设备令牌我怎么能发送推送通知.谁能告诉我如何获得设备令牌.
I understood how to send notification. But without devicetoken how can i send push notification. Can anybosy tell me how can i get the device token.
推荐答案
我关注了 本教程 直接有效.它还解释了如何获取设备令牌.
I followed this tutorial which worked very well directly. It also explains how to get the device token.
它会提醒您输入,但您也可以将手机连接到计算机并阅读 logcat 文件.(可以使用android SDK中的监控"工具)
It is alerted for you to type it over, but you can also hook your phone up to your computer and read the logcat files. (You can use the "monitor" tool in the android SDK)
更新示例
大多数步骤基本上是我之前提到的 devgirls 教程
在 Windows 命令提示符下:
In windows command prompt:
phonegap 创建快速推送cd quickpushphonegap 本地构建 androidphonegap 本地插件添加 https://github.com/phonegap-build/PushPlugin
我跳过了这个,我没有将文件复制到 www 目录.我只是把它留在原处.
I skipped this, I dont copy the file to the www dir. I just leave it where it is.
将 添加到 index.html
add <script type="text/javascript" src="PushNotification.js"></script> to index.html
添加<gap:plugin name="com.phonegap.plugins.pushplugin"/> 到config.xml(这与站点不同,解决了不支持的错误)
add <gap:plugin name="com.phonegap.plugins.pushplugin" /> to config.xml (this is different from site and solves not supported error)
复制/js/index.js文件中onDeviceReady函数中的推送代码.显然从谷歌添加你自己的密钥
Copy the push code in the onDeviceReady function in /js/index.js file. Obviously add your own key from google
alert('device ready');
try {
var pushNotification = window.plugins.pushNotification;
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"--SENDER ID FROM GOOGLE--","ecb":"app.onNotificationGCM"});
} catch (ex) {
alert('error: ' + ex);
}
复制/js/index.js文件中的回调处理函数
Copy the callback handler function in /js/index.js file
successHandler: function(result) {
alert('Callback Success! Result = '+result)
},
errorHandler:function(error) {
alert(error);
},
onNotificationGCM: function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Regid " + e.regid);
alert('registration id = '+e.regid);
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = '+e.message+' msgcnt = '+e.msgcnt);
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
构建应用程序:phonegap remote build android
这篇关于如何使用phonegap和解析发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)