h5 消息推送 jpush-phonegap-plugin 插件的使用
2016-10-18 15:47
344 查看
1.安装jpush-phonegap-plugin插件
安装命令 记得把your_jpush_appkey更换成自己的appkey,获取appkey的方法这里就不说了(官网地址:https://www.jiguang.cn/ )
通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+:
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
或直接通过 url 安装:
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
或下载到本地安装:
cordova plugin add Your_Plugin_Path --variable API_KEY=your_jpush_appkey
github地址:https://github.com/jpush/jpush-phonegap-plugin
2.android端安装成功之后(如果安装失败,请更换不通的方法重新安装,尽量清理干净以前安装出错的)
app.js中添加一下两句代码,打包之后就可以进行推送消息了!3.安卓端自定义通知的样式(重点来啦)
修改JPushPlugin.java 下的setCustomPushNotificationBuilder方法,如图CustomPushNotificationBuilder(MainActivity.this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text); // 指定定制的 Notification Layout builder.statusBarDrawable = R.drawable.your_notification_icon; // 指定最顶层状态栏小图标 builder.layoutIconDrawable = R.drawable.your_2_notification_icon; // 指定下拉状态栏时显示的通知图标 JPushInterface.setPushNotificationBuilder(2, builder);注意:your_notification_icon必须放在 android的res/drawable-hdpi下面,记得导入R文件哦 import 你的包名.R,customer_notitfication_layout样式布局,可以自定义哦;
然后需要在js中调用setCustomPushNotificationBuilder方法,如图
官网说明:https://docs.jiguang.cn/jpush/client/Android/android_senior/#_8
4.接收通知栏的消息
监听jpush.openNotification,如图代码(方便复制):
document.addEventListener("jpush.openNotification", function(event){ var alertContent; if(device.platform == "Android") { alertContent = event.alert; } else { alertContent = event.aps.alert; } alert("open Notificaiton:" + alertContent); }, false);github地址:https://github.com/jpush/jpush-phonegap-plugin
相关文章推荐
- [转]PhoneGap使用PushPlugin插件实现消息推送
- PhoneGap使用PushPlugin插件实现消息推送
- 使用chrome浏览器插件Chrome Poster为GCM推送消息
- cordova二维码扫描插件phonegap-plugin-barcodescanner使用及坑点
- 消息推送之Jpush极光推送使用心得
- jpush-react-native 插件的集成与使用 Android 篇(推送)
- php使用JPush极光推送ios android通知消息
- Titanium 使用刘明星的Jpush module做android端的消息推送
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
- 跨平台移动开发 Android使用JPush推送消息
- PhoneGap极光推送插件使用
- Swift - JPush极光推送的使用(发送自定义消息/通知/别名/tag)
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
- 使用docker-maven-plugin插件构建和推送Docker映像
- Android和h5混合开发框架:CordovaPlugin插件使用说明
- 使用第三方推送平台JPUSH推送消息到android手机
- ionic如何在线安装jpush-phonegap-plugin插件
- phonegap添加消息推送插件教程
- ionic 之cordova 极光推送jpush和百度定位插件结合使用之定位失效问题解决办法
- 【PhoneGap Android】Google GCM推送使用插件