Str*_*per 9 php jquery android cordova parse-platform
我正在使用php,jquery和phonegap创建一个Android应用程序.我在谷歌搜索了很多东西,但我无法发送推送通知.我已经看过这个Phonegap和Parse.com推送通知IOS但我不清楚我可以获得deviceToken.
我也见过以下
https://parse.com/questions/php-rest-example-of-targeted-push
我明白了如何发送通知.但没有devicetoken我怎么能发送推送通知.Anybosy可以告诉我如何获得设备令牌.
Hug*_*ing 12
我按照本教程直接进行了很好的工作.它还解释了如何获取设备令牌.
系统会提醒您输入它,但您也可以将手机连接到计算机并读取logcat文件.(你可以使用android SDK中的"监视器"工具)
更新示例
大多数步骤基本上都是我之前提到的devgirls教程的直接副本
在Windows命令提示符下:
phonegap create quickpushcd quickpushphonegap local build androidphonegap local plugin add https://github.com/phonegap-build/PushPlugin
我跳过这个,我不把文件复制到www目录.我把它放在原处.
添加<script type="text/javascript" src="PushNotification.js"></script>到index.html
添加<gap:plugin name="com.phonegap.plugins.pushplugin" />到config.xml(这与站点不同,并解决了不支持的错误)
复制/js/index.js文件中onDeviceReady函数中的推送代码.显然,从谷歌添加自己的密钥
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);
}
Run Code Online (Sandbox Code Playgroud)复制/js/index.js文件中的回调处理函数
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;
}
}
Run Code Online (Sandbox Code Playgroud)构建应用程序: phonegap remote build android
| 归档时间: |
|
| 查看次数: |
12722 次 |
| 最近记录: |