cordova的android notify消息通知插件
最近在学习用CORDOVA(PHONEGAP)结合SENCHA TOUCH开发应用,想实现一个安卓下的消息通知功能,这个可以通过CORDOVA的插件来实现。
插件目录结构如下:
notifyplugin
- plugin.xml
- www/notifysrv.js
- src/android/NotifysrvPlugin.java
- libs/android-support-v4.jar
先编写plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.elon.cordova.plugin" version="0.0.1">
<name>NotifysrvPlugin</name>
<description>NotifysrvPlugin Description</description>
<author>elon</author>
<license>Apache 2.0 License</license>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module src="www/notifysrv.js" name="notifysrv">
<clobbers target="Notify" />
</js-module>
<platform name="android">
<source-file src="src/android/NotifysrvPlugin.java"
target-dir="src/com/elon/cordova/plugin" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="NotifysrvPlugin">
<param name="android-package" value="com.elon.cordova.plugin.NotifysrvPlugin"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.VIBRATE" />
</config-file>
</platform>
</plugin>

NotifysrvPlugin.java

package com.elon.cordova.plugin; import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaInterface; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; import android.content.Context;
import android.support.v4.app.NotificationCompat; public class NotifysrvPlugin extends CordovaPlugin {
public static final String TAG = "NotifysrvPlugin";
public static final String iconname = "icon";//icon res name public NotificationManager nm;
public Context m_context;
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
m_context = this.cordova.getActivity().getApplicationContext();
nm = (NotificationManager) m_context.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
} @Override
public boolean execute(String action, JSONArray args,
CallbackContext callbackContext) throws JSONException {
if ("send".equals(action)) {
String title = args.getString(0);
String text = args.getString(1); PendingIntent m_PendingIntent=PendingIntent.getActivity(this.cordova.getActivity(),
0, this.cordova.getActivity().getIntent(), 0);
int iconResID = m_context.getResources().getIdentifier(iconname,"drawable", m_context.getPackageName());
Notification notification = new NotificationCompat.Builder(m_context)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_ALL) //设置默认铃声,震动等
.setSmallIcon(iconResID)
.setContentIntent(m_PendingIntent)
.setAutoCancel(true)
// .setLargeIcon(aBitmap)
.build(); nm.notify(1, notification);
callbackContext.success();
return true;
}
return false;
}
}

notifysrv.js

var argscheck = require('cordova/argscheck');
var exec = require('cordova/exec');
var Notify = function() {};
Notify.prototype.send = function(message, success, error) {
//argscheck.checkArgs('AFF', 'notify.send', arguments);
console.log("send notification["+message[1]+"]");
if(!message)
error && error("please input message");
else
exec(success, error, 'NotifysrvPlugin', 'send', message);
};
var notify = new Notify();
module.exports = notify;

将插件加入cordova工程的办法
进入CMD,进入cordova工程文件夹,然后输入如下命令
cordova plugin add [插件目录]
使用本插件的方法:

var msg = ["新消息标题","新的消息内容"];
Notify.send(msg,function(){
console.log("成功");
},function(msg){
console.log(msg || "失败");
});

cordova的android notify消息通知插件的更多相关文章
- Android Notification 消息通知 相关资料.md
目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...
- PNotify – 简单易用的 JS 通知,消息提示插件
PNotify 是一个 JavaScript 通知插件,前身为 Pines Notify.它旨在提供无与伦比的灵活性,同时很容易使用.它可以提供无阻塞的通知,允许用户无需关闭通知或者提示信息就可以点击 ...
- Android中的消息通知(NotificationManager和Notification)
下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- Android消息通知-Notification
Android中常用的消息提醒,一种是Toast弹出提醒内容,一种是AlterDialog弹出框来提醒用户,还有一种就是消息通知的,用Android经常收到各种通知就是Notifation.Notif ...
- Android学习系列(7)--App消息通知机制
有人说,程序员很安静,但我不完全同意,程序员的聒噪,是藏在代码后面,是藏在程序后面.这篇文章是Android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. 1.消息推送机制 ...
- Android移动APP开发笔记——Cordova(PhoneGap)通过CordovaPlugin插件调用 Activity 实例
引言 Cordova(PhoneGap)采用的是HTML5+JavaScript混合模式来开发移动手机APP,因此当页面需要获取手机内部某些信息时(例如:联系人信息,坐标定位,短信等),程序就需要调用 ...
- jenkins 构建后发送钉钉消息通知(插件)
钉钉,越来越多的公司采用,那么我们在持续集成中,也可以直接选择钉钉插件的,在之前的博客中 ,对发送的钉钉消息进行了定制,那样的话会开启一个新的任务, 其实今天呢,我们可以直接安装一个插件就可以发送了, ...
- 强大的响应式jQuery消息通知框和信息提示框插件
lobibox是一款功能很强大的jQuery消息通知框和信息提示框插件.这个插件分为两个部分:消息通知框和信息提示框.它能很好的结合Bootstrap使用. 信息提示框 lobibox的信息提示框能够 ...
随机推荐
- HDOJ 1301
9852303 2013-12-18 11:47:01 Accepted 1301 0MS 264K 1117 B C++ 泽泽 Jungle Roads Time Limit: 2000/1000 ...
- django 1.7 新特性 --- data migration
官方文档:https://docs.djangoproject.com/en/dev/topics/migrations/ 1.7 之前大家可能会用south用于管理数据库的模型的同步.1.7之后dj ...
- codeforces 479B Towers 解题报告
题目链接:http://codeforces.com/problemset/problem/479/B 题目意思:有 n 座塔,第 i 座塔有 ai 个cubes在上面.规定每一次操作是从最多 cub ...
- MVC增删改查例子
一.显示用户列表1.新建UserInfoController控制器 public ActionResult Index() { DataTable table = SQLHelper.ExecuteR ...
- struts2中各种值栈问题
struts2中OGNL和 ValueStack(一) 收藏 学习的时候,总分不清楚在struts2中页面的传值和取值是怎么来完成的,所以从网上搜了很多资料,现在把这些资料总结写,留着以后参考..看完 ...
- poj 3253:Fence Repair(堆排序应用)
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 23913 Accepted: 7595 Des ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- GRE词汇3-4 +
page3 accommodate: common commodity accompany: Accomplice: com—共同 plic—重叠 Complicate duplicate repl ...
- 免费电子书:微软Azure基础之Azure Automation
(此文章同时发表在本人微信公众号"dotNET每日精华文章") Azure Automation是Azure内置的一项自动化运维基础功能,微软为了让大家更快上手使用这项功能,特意推 ...
- loj 1165(bfs+康托展开)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26879 思路:题目意思很简单,就是通过一些位置的交换,最后变成有序 ...