Compare commits

...

18 Commits

Author SHA1 Message Date
Hevin
3101dcdd8e Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-20 14:41:42 +08:00
Hevin
a46da92fa1 Format js file. 2016-07-20 14:40:40 +08:00
Hevin
5547d5716e Update event callback. 2016-07-20 14:34:35 +08:00
Hevin
7da0a25db0 Format js. 2016-07-19 17:15:40 +08:00
Hevin
0c74ff328d Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-19 17:13:58 +08:00
Hevin
2065ad44ce Format README. 2016-07-18 16:39:15 +08:00
Hevin
cbe8e511f2 Update README 2016-07-18 16:06:14 +08:00
Hevin
9a47c88873 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-16 00:17:25 +08:00
Hevin
684039b044 Format README 2016-07-15 18:02:02 +08:00
Hevin
356de48d31 Format README 2016-07-15 18:00:39 +08:00
Hevin
d412b10d3e Update README 2016-07-15 17:56:39 +08:00
Hevin
44345d9753 Merge remote-tracking branch 'refs/remotes/origin/dev' 2016-07-13 23:08:30 +08:00
Hevin
5f93fc3f49 Update API to don't depend support lib. 2016-07-13 23:07:01 +08:00
Hevin
673a402c51 Merge remote-tracking branch 'refs/remotes/origin/master' into dev 2016-07-13 22:23:37 +08:00
Hevin
09e0d62360 Update README 2016-07-13 22:03:35 +08:00
Hevin
b4830d4ef7 Remove dependency. 2016-07-13 16:34:40 +08:00
Hevin
2c3bf53792 Update npm version. 2016-07-12 14:57:58 +08:00
Hevin
78ebe0e787 Update plugin id. 2016-07-12 14:51:20 +08:00
7 changed files with 443 additions and 442 deletions

View File

@@ -2,40 +2,39 @@
[![Build Status](https://travis-ci.org/jpush/jpush-phonegap-plugin.svg?branch=master)](https://travis-ci.org/jpush/jpush-phonegap-plugin)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-413602425-red.svg)]()
[![release](https://img.shields.io/badge/release-2.2.1-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![release](https://img.shields.io/badge/release-2.2.4-blue.svg)](https://github.com/jpush/jpush-phonegap-plugin/releases)
[![platforms](https://img.shields.io/badge/platforms-iOS%7CAndroid-lightgrey.svg)](https://github.com/jpush/jpush-phonegap-plugin)
[![weibo](https://img.shields.io/badge/weibo-JPush-blue.svg)](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
支持 iOS, Android 的 Cordova 推送插件。
> 如需要 IM 功能的插件,可关注 [JMessage PhoneGap Plugin](https://github.com/jpush/jmessage-phonegap-plugin)。
> QQ 交流群413602425
> 如需要短信验证码功能的插件,可关注 [JSMS Cordova Plugin](https://github.com/jpush/cordova-plugin-jsms)。
> QQ 交流群413602425。
## 集成步骤
集成 JPush PhoneGap Plugin 有两种方法:
### 在线安装
- 通过 Cordova Plugins 安装,要求 PhoneGap/Cordova CLI 5.0+
- 先安装 cordova-plugin-device 插件:
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
cordova plugin add cordova-plugin-device
- 直接通过 url 安装:
- 安装本插件
- 通过 Cordova Plugins 安装,要求 Cordova CLI 5.0+
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
cordova plugin add jpush-phonegap-plugin --variable API_KEY=your_jpush_appkey
### 本地安装
使用 git 命令将 JPush PhoneGap 插件下载的本地,目录标记为 $JPUSH_PLUGIN_DIR
- 或者直接通过 url 安装:
git clone https://github.com/jpush/jpush-phonegap-plugin.git
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
- 或下载到本地安装:
- [Android 手动安装文档地址](/doc/Android_handle_install.md)。
cordova plugin add Your_Plugin_Path --variable API_KEY=your_jpush_appkey
- [iOS 手动安装文档地址](/doc/iOS_install.md)。
## Demo
插件项目中包含一个简单的 Demo。若想参考可以在 /example 文件夹内找到并拷贝以下文件:
插件项目中包含一个简单的 Demo。若想参考可以在 */example* 文件夹内找到并拷贝以下文件:
src/example/index.html -> www/index.html
src/example/css/* -> www/css
@@ -69,16 +68,13 @@
中的代码cordova build 可能会导致对 AndroidManifest.xml 的修改。
Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.html)。
### 1. Android
### Android
Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
- Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be resolved to a type*。
解决方案Eclipse 中右键单击工程名Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
解决方案Eclipse 中右键单击工程名Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
### 2. iOS
- 收不到推送:
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
### iOS
- 设置 PushConfig.plist
- APP_KEY应用标识。
@@ -87,8 +83,11 @@ Eclipse 中 import PhoneGap 工程之后出现:*Type CallbackContext cannot be
- IsIDFA是否使用 IDFA 启动 SDK。
- 收不到推送:
请首先按照正确方式再次配置证书、描述文件,具体可参考 [iOS 证书设置指南](http://docs.jpush.io/client/ios_tutorials/#ios_1)。
## 更多
- QQ 群413602425
- [JPush 官网文档](http://docs.jpush.io/)
- 如有问题可访问[极光社区](http://community.jpush.cn/)。
- QQ 群413602425
- [JPush 官网文档](http://docs.jpush.io/)
- 如有问题可访问[极光社区](http://community.jiguang.cn/)。

View File

@@ -226,7 +226,7 @@ JPush SDK 会以广播的形式发送 RegistrationID 到应用程序。
var alertContent;
if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -280,7 +280,7 @@ ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.o
var alertContent;
if(device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -339,7 +339,7 @@ ps点击通知后传递的 json object 保存在 window.plugins.jPushPlugin.r
try{
var message
if(device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
message = event.message;
} else {
message = event.content;
}

View File

@@ -47,7 +47,7 @@
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.openNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -61,7 +61,7 @@
try {
var alertContent;
if (device.platform == "Android") {
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
alertContent = event.alert;
} else {
alertContent = event.aps.alert;
}
@@ -75,7 +75,7 @@
try {
var message;
if (device.platform == "Android") {
message = window.plugins.jPushPlugin.receiveMessage.message;
message = event.message;
} else {
message = event.content;
}

View File

@@ -1,9 +1,9 @@
{
"name": "jpush-phonegap-plugin",
"version": "2.2.2",
"version": "2.2.5",
"description": "JPush for cordova plugin",
"cordova": {
"id": "cordova-plugin-JPush",
"id": "jpush-phonegap-plugin",
"platforms": [
"ios",
"android"

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-JPush"
version="2.2.2">
xmlns:android="http://schemas.android.com/apk/res/android"
id="jpush-phonegap-plugin"
version="2.2.4">
<name>JPush Plugin</name>
<description>JPush for cordova plugin</description>
@@ -13,187 +13,167 @@
<preference name="API_KEY" />
<engines>
<engine name="cordova" version=">=3.0"/>
<engine name="cordova" version=">=3.0" />
</engines>
<dependency id="org.apache.cordova.device" url="https://github.com/apache/cordova-plugin-device.git"/>
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
<clobbers target="JPush"/>
<clobbers target="JPush" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin"/>
</feature>
</config-file>
<config-file target="config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="ios-package" value="JPushPlugin" />
</feature>
</config-file>
<header-file src="src/ios/Plugins/JPushPlugin.h"/>
<source-file src="src/ios/Plugins/JPushPlugin.m"/>
<header-file src="src/ios/Plugins/JPushPlugin.h" />
<source-file src="src/ios/Plugins/JPushPlugin.m" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.8.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h"/>
<source-file src="src/ios/Plugins/AppDelegate+JPush.m"/>
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="libz.tbd" weak="true" />
<framework src="AdSupport.framework" weak="true" />
<header-file src="src/ios/lib/JPUSHService.h" />
<source-file src="src/ios/lib/jpush-ios-2.1.8.a" framework="true" />
<header-file src="src/ios/Plugins/AppDelegate+JPush.h" />
<source-file src="src/ios/Plugins/AppDelegate+JPush.m" />
<resource-file src="src/ios/PushConfig.plist" />
<framework src="CFNetwork.framework" weak="true" />
<framework src="CoreFoundation.framework" weak="true" />
<framework src="CoreTelephony.framework" weak="true" />
<framework src="SystemConfiguration.framework" weak="true" />
<framework src="CoreGraphics.framework" weak="true" />
<framework src="Foundation.framework" weak="true" />
<framework src="UIKit.framework" weak="true" />
<framework src="Security.framework" weak="true" />
<framework src="libz.tbd" weak="true" />
<framework src="AdSupport.framework" weak="true" />
<config-file target="*PushConfig.plist" parent="APP_KEY">
<string>$API_KEY</string>
</config-file>
</platform>
<config-file target="*PushConfig.plist" parent="APP_KEY">
<string>$API_KEY</string>
</config-file>
</platform>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="JPushPlugin">
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin"/>
<param name="android-package" value="cn.jpush.phonegap.JPushPlugin" />
</feature>
</config-file>
<framework src="com.android.support:support-v4:24.0.0" />
<config-file target="AndroidManifest.xml" parent="/manifest">
<!-- Required 一些系统要求的权限,如访问网络等-->
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<permission
android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" android:protectionLevel="signature" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<!-- Required SDK核心功能-->
<activity
android:name="cn.jpush.android.ui.PushActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden">
<activity android:name="cn.jpush.android.ui.PushActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="cn.jpush.android.ui.PushActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="$PACKAGE_NAME"/>
<action android:name="cn.jpush.android.ui.PushActivity" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</activity>
<!-- Rich push 核心功能 since 2.0.6-->
<activity
android:name="cn.jpush.android.ui.PopWinActivity"
android:theme="@style/MyDialogStyle"
android:exported="false">
<activity android:name="cn.jpush.android.ui.PopWinActivity" android:theme="@style/MyDialogStyle" android:exported="false">
</activity>
<!-- Required SDK核心功能-->
<service
android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
<service android:name="cn.jpush.android.service.DownloadService"
android:enabled="true"
android:exported="false">
</service>
<!-- Required SDK 核心功能-->
<service
android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<service android:name="cn.jpush.android.service.PushService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTER"/>
<action android:name="cn.jpush.android.intent.REPORT"/>
<action android:name="cn.jpush.android.intent.PushService"/>
<action android:name="cn.jpush.android.intent.PUSH_TIME"/>
<action android:name="cn.jpush.android.intent.REGISTER" />
<action android:name="cn.jpush.android.intent.REPORT" />
<action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter>
</service>
<!-- Required SDK核心功能-->
<receiver
android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<receiver android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!--Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<!-- Optional -->
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
</intent-filter>
</receiver>
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<service
android:name="cn.jpush.android.service.DaemonService"
android:enabled="true"
android:exported="true">
<intent-filter >
<service android:name="cn.jpush.android.service.DaemonService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.DaemonService" />
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</service>
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver
android:name="cn.jpush.phonegap.MyReceiver"
android:enabled="true">
<receiver android:name="cn.jpush.phonegap.MyReceiver" android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
<!-- Required 显示通知栏 -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION"/>
<action android:name="cn.jpush.android.intent.REGISTRATION" />
<!-- Required 用户注册SDK的intent -->
<action android:name="cn.jpush.android.intent.UNREGISTRATION"/>
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
<action android:name="cn.jpush.android.intent.UNREGISTRATION" />
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
<!-- Required 用户接收SDK消息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
<!-- Required 用户接收SDK通知栏信息的intent -->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
<!-- Required 用户打开自定义通知栏的intent -->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK"/>
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />
<!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
<category android:name="$PACKAGE_NAME"/>
<category android:name="$PACKAGE_NAME" />
</intent-filter>
</receiver>
<!-- Required SDK核心功能-->
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<receiver android:name="cn.jpush.android.service.AlarmReceiver" />
<!-- Required. Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" />
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY" />
</config-file>
<source-file src="src/android/jpush-android-2.1.7.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush217.so" target-dir="libs/armeabi"/>
<source-file src="src/android/armeabi-v7a/libjpush217.so" target-dir="libs/armeabi-v7a"/>
<source-file src="src/android/arm64-v8a/libjpush217.so" target-dir="libs/arm64-v8a"/>
<source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86"/>
<source-file src="src/android/x86_64/libjpush217.so" target-dir="libs/x86_64"/>
<source-file src="src/android/jpush-android-2.1.7.jar" target-dir="libs" />
<source-file src="src/android/armeabi/libjpush217.so" target-dir="libs/armeabi" />
<source-file src="src/android/armeabi-v7a/libjpush217.so" target-dir="libs/armeabi-v7a" />
<source-file src="src/android/arm64-v8a/libjpush217.so" target-dir="libs/arm64-v8a" />
<source-file src="src/android/x86/libjpush217.so" target-dir="libs/x86" />
<source-file src="src/android/x86_64/libjpush217.so" target-dir="libs/x86_64" />
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable"/>
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap" />
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap" />
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout" />
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable" />
<!-- Rich Push resources -->
<source-file src="src/android/ic_richpush_actionbar_back.png" target-dir="res/drawable" />

View File

@@ -1,8 +1,11 @@
package cn.jpush.phonegap;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AppOpsManager;
import android.content.Context;
import android.support.v4.app.NotificationManagerCompat;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
@@ -14,6 +17,8 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
@@ -138,7 +143,7 @@ public class JPushPlugin extends CordovaPlugin {
}
private static JSONObject getMessageObject(String message,
Map<String, Object> extras) {
Map<String, Object> extras) {
JSONObject data = new JSONObject();
try {
data.put("message", message);
@@ -172,7 +177,7 @@ public class JPushPlugin extends CordovaPlugin {
}
private static JSONObject getNotificationObject(String title,
String alert, Map<String, Object> extras) {
String alert, Map<String, Object> extras) {
JSONObject data = new JSONObject();
try {
data.put("title", title);
@@ -180,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
JSONObject jExtras = new JSONObject();
for (Entry<String, Object> entry : extras.entrySet()) {
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
JSONObject jo = null;
JSONObject jo;
if (TextUtils.isEmpty((String) entry.getValue())) {
jo = new JSONObject();
} else {
@@ -222,7 +227,7 @@ public class JPushPlugin extends CordovaPlugin {
}
static void transmitNotificationOpen(String title, String alert,
Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) {
return;
}
@@ -240,7 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
}
static void transmitNotificationReceive(String title, String alert,
Map<String, Object> extras) {
Map<String, Object> extras) {
if (instance == null) {
return;
}
@@ -259,7 +264,7 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public boolean execute(final String action, final JSONArray data,
final CallbackContext callbackContext) throws JSONException {
final CallbackContext callbackContext) throws JSONException {
if (!methodList.contains(action)) {
return false;
}
@@ -314,13 +319,11 @@ public class JPushPlugin extends CordovaPlugin {
}
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
NotificationManagerCompat nmc = NotificationManagerCompat.from(
cordova.getActivity().getApplicationContext());
int isEnabled;
if (nmc.areNotificationsEnabled()) {
if (hasPermission("OP_POST_NOTIFICATION")) {
isEnabled = 1;
} else {
isEnabled = 0;
isEnabled = 0;
}
callback.success(isEnabled);
}
@@ -436,7 +439,7 @@ public class JPushPlugin extends CordovaPlugin {
}
void setBasicPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
CallbackContext callbackContext) {
BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(
this.cordova.getActivity());
builder.developerArg0 = "Basic builder 1";
@@ -450,22 +453,16 @@ public class JPushPlugin extends CordovaPlugin {
}
/**
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
* 自定义推送通知栏样式,需要自己实现具体代码。
* http://docs.jiguang.cn/client/android_tutorials/#_11
*/
void setCustomPushNotificationBuilder(JSONArray data,
CallbackContext callbackContext) {
CallbackContext callbackContext) {
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
// this.cordova.getActivity(), R.layout.test_notification_layout,
// R.id.icon, R.id.title, R.id.text);
// builder.developerArg0 = "Custom Builder 1";
// JPushInterface.setPushNotificationBuilder(2, builder);
// JSONObject obj = new JSONObject();
// try {
// obj.put("id", 2);
// } catch (JSONException e) {
// e.printStackTrace();
// }
// JPushInterface.setDefaultPushNotificationBuilder(builder);
}
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
@@ -600,4 +597,37 @@ public class JPushPlugin extends CordovaPlugin {
}
};
@TargetApi(Build.VERSION_CODES.KITKAT)
private boolean hasPermission(String appOpsServiceId) {
Context context = cordova.getActivity().getApplicationContext();
AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
ApplicationInfo appInfo = context.getApplicationInfo();
String pkg = context.getPackageName();
int uid = appInfo.uid;
Class appOpsClazz = null;
try {
appOpsClazz = Class.forName(AppOpsManager.class.getName());
Method checkOpNoThrowMethod = appOpsClazz.getMethod("checkOpNoThrow",
Integer.TYPE, Integer.TYPE, String.class);
Field opValue = appOpsClazz.getDeclaredField(appOpsServiceId);
int value = opValue.getInt(Integer.class);
Object result = checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg);
return Integer.parseInt(result.toString()) == AppOpsManager.MODE_ALLOWED;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return true;
}
}

View File

@@ -1,215 +1,210 @@
var JPushPlugin = function () {}
var JPushPlugin = function(){
};
//private plugin function
// private plugin function
JPushPlugin.prototype.receiveMessage = {}
JPushPlugin.prototype.openNotification = {}
JPushPlugin.prototype.receiveNotification = {}
JPushPlugin.prototype.isPlatformIOS = function() {
var isPlatformIOS = device.platform == "iPhone"
|| device.platform == "iPad"
|| device.platform == "iPod touch"
|| device.platform == "iOS";
return isPlatformIOS;
JPushPlugin.prototype.isPlatformIOS = function () {
var isPlatformIOS = device.platform == 'iPhone'
|| device.platform == 'iPad'
|| device.platform == 'iPod touch'
|| device.platform == 'iOS'
return isPlatformIOS
}
JPushPlugin.prototype.error_callback = function(msg) {
console.log("Javascript Callback Error: " + msg);
JPushPlugin.prototype.error_callback = function (msg) {
console.log('Javascript Callback Error: ' + msg)
}
JPushPlugin.prototype.call_native = function(name, args, callback) {
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args);
return ret;
JPushPlugin.prototype.call_native = function (name, args, callback) {
ret = cordova.exec(callback, this.error_callback, 'JPushPlugin', name, args)
return ret
}
// public methods
JPushPlugin.prototype.init = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("initial", data, null);
} else {
data = [];
this.call_native("init", data, null);
}
JPushPlugin.prototype.init = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('initial', data, null)
} else {
data = []
this.call_native('init', data, null)
}
}
JPushPlugin.prototype.getRegistrationID = function(callback) {
try {
var data = [];
this.call_native("getRegistrationID", [data], callback);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.getRegistrationID = function (callback) {
try {
var data = []
this.call_native('getRegistrationID', [data], callback)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.stopPush = function() {
data = [];
this.call_native("stopPush", data, null);
JPushPlugin.prototype.stopPush = function () {
data = []
this.call_native('stopPush', data, null)
}
JPushPlugin.prototype.resumePush = function() {
data = [];
this.call_native("resumePush", data, null);
JPushPlugin.prototype.resumePush = function () {
data = []
this.call_native('resumePush', data, null)
}
JPushPlugin.prototype.isPushStopped = function(callback) {
data = [];
this.call_native("isPushStopped", data, callback);
JPushPlugin.prototype.isPushStopped = function (callback) {
data = []
this.call_native('isPushStopped', data, callback)
}
// iOS methods
JPushPlugin.prototype.setTagsWithAlias = function(tags, alias) {
try {
if(tags == null) {
this.setAlias(alias);
return;
}
if(alias == null) {
this.setTags(tags);
return;
}
var arrayTagWithAlias = [tags];
arrayTagWithAlias.unshift(alias);
this.call_native("setTagsWithAlias", arrayTagWithAlias, null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setTags = function(tags) {
try {
this.call_native("setTags", tags, null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setAlias = function(alias) {
try {
this.call_native("setAlias", [alias], null);
} catch(exception) {
console.log(exception);
}
}
JPushPlugin.prototype.setBadge = function(value) {
if(this.isPlatformIOS()) {
try {
this.call_native("setBadge", [value], null);
} catch(exception) {
console.log(exception);
}
}
}
JPushPlugin.prototype.resetBadge = function() {
if(this.isPlatformIOS()) {
try {
var data = [];
this.call_native("resetBadge", [data], null);
} catch(exception) {
console.log(exception);
}
}
}
JPushPlugin.prototype.setDebugModeFromIos = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("setDebugModeFromIos", [data], null);
}
}
JPushPlugin.prototype.setLogOFF = function() {
if(this.isPlatformIOS()) {
var data = [];
this.call_native("setLogOFF", [data], null);
}
}
JPushPlugin.prototype.setCrashLogON = function() {
if (this.isPlatformIOS()) {
var data = [];
this.call_native("crashLogON", [data], null);
JPushPlugin.prototype.setTagsWithAlias = function (tags, alias) {
try {
if (tags == null) {
this.setAlias(alias)
return
}
}
JPushPlugin.prototype.addLocalNotificationForIOS = function(delayTime, content,
badge, notificationID, extras) {
if (this.isPlatformIOS()) {
var data = [delayTime, content, badge, notificationID, extras];
this.call_native("setLocalNotification", data, null);
if (alias == null) {
this.setTags(tags)
return
}
var arrayTagWithAlias = [tags]
arrayTagWithAlias.unshift(alias)
this.call_native('setTagsWithAlias', arrayTagWithAlias, null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function(
identifierKey) {
if (this.isPlatformIOS()) {
var data = [identifierKey];
this.call_native("deleteLocalNotificationWithIdentifierKey", data, null);
JPushPlugin.prototype.setTags = function (tags) {
try {
this.call_native('setTags', tags, null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.setAlias = function (alias) {
try {
this.call_native('setAlias', [alias], null)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.setBadge = function (value) {
if (this.isPlatformIOS()) {
try {
this.call_native('setBadge', [value], null)
} catch(exception) {
console.log(exception)
}
}
}
JPushPlugin.prototype.clearAllLocalNotifications = function(){
if (this.isPlatformIOS()) {
var data = [];
this.call_native("clearAllLocalNotifications", data, null);
JPushPlugin.prototype.resetBadge = function () {
if (this.isPlatformIOS()) {
try {
var data = []
this.call_native('resetBadge', [data], null)
} catch(exception) {
console.log(exception)
}
}
}
JPushPlugin.prototype.setLocation = function(latitude, longitude){
if (this.isPlatformIOS()) {
var data = [latitude, longitude];
this.call_native("setLocation", data, null);
}
JPushPlugin.prototype.setDebugModeFromIos = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('setDebugModeFromIos', [data], null)
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function(data) {
try {
console.log("JPushPlugin:receiveMessageIniOSCallback--data:" + data);
var bToObj = JSON.parse(data);
var content = bToObj.content;
console.log(content);
} catch(exception) {
console.log("JPushPlugin:receiveMessageIniOSCallback" + exception);
}
JPushPlugin.prototype.setLogOFF = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('setLogOFF', [data], null)
}
}
JPushPlugin.prototype.startLogPageView = function(pageName) {
if(this.isPlatformIOS()) {
this.call_native("startLogPageView", [pageName], null);
}
JPushPlugin.prototype.setCrashLogON = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('crashLogON', [data], null)
}
}
JPushPlugin.prototype.stopLogPageView = function(pageName) {
if(this.isPlatformIOS()) {
this.call_native("stopLogPageView", [pageName], null);
}
JPushPlugin.prototype.addLocalNotificationForIOS = function (delayTime, content,
badge, notificationID, extras) {
if (this.isPlatformIOS()) {
var data = [delayTime, content, badge, notificationID, extras]
this.call_native('setLocalNotification', data, null)
}
}
JPushPlugin.prototype.beginLogPageView = function(pageName, duration) {
if(this.isPlatformIOS()) {
this.call_native("beginLogPageView", [pageName, duration], null);
}
JPushPlugin.prototype.deleteLocalNotificationWithIdentifierKeyInIOS = function (
identifierKey) {
if (this.isPlatformIOS()) {
var data = [identifierKey]
this.call_native('deleteLocalNotificationWithIdentifierKey', data, null)
}
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function(badge) {
if(this.isPlatformIOS()) {
this.call_native("setApplicationIconBadgeNumber", [badge], null);
}
JPushPlugin.prototype.clearAllLocalNotifications = function () {
if (this.isPlatformIOS()) {
var data = []
this.call_native('clearAllLocalNotifications', data, null)
}
}
JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
if(this.isPlatformIOS()) {
this.call_native("getApplicationIconBadgeNumber", [], callback);
}
JPushPlugin.prototype.setLocation = function (latitude, longitude) {
if (this.isPlatformIOS()) {
var data = [latitude, longitude]
this.call_native('setLocation', data, null)
}
}
JPushPlugin.prototype.receiveMessageIniOSCallback = function (data) {
try {
console.log('JPushPlugin:receiveMessageIniOSCallback--data:' + data)
var bToObj = JSON.parse(data)
var content = bToObj.content
console.log(content)
} catch(exception) {
console.log('JPushPlugin:receiveMessageIniOSCallback' + exception)
}
}
JPushPlugin.prototype.startLogPageView = function (pageName) {
if (this.isPlatformIOS()) {
this.call_native('startLogPageView', [pageName], null)
}
}
JPushPlugin.prototype.stopLogPageView = function (pageName) {
if (this.isPlatformIOS()) {
this.call_native('stopLogPageView', [pageName], null)
}
}
JPushPlugin.prototype.beginLogPageView = function (pageName, duration) {
if (this.isPlatformIOS()) {
this.call_native('beginLogPageView', [pageName, duration], null)
}
}
JPushPlugin.prototype.setApplicationIconBadgeNumber = function (badge) {
if (this.isPlatformIOS()) {
this.call_native('setApplicationIconBadgeNumber', [badge], null)
}
}
JPushPlugin.prototype.getApplicationIconBadgeNumber = function (callback) {
if (this.isPlatformIOS()) {
this.call_native('getApplicationIconBadgeNumber', [], callback)
}
}
// 判断系统设置中是否对本应用启用通知。
// iOS: 返回值如果大于 0代表通知开启0: 通知关闭。
@@ -219,162 +214,159 @@ JPushPlugin.prototype.getApplicationIconBadgeNumber = function(callback) {
// UIRemoteNotificationTypeAlert = 1 << 2,
// UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
// Android: 返回值 1 代表通知启用、0: 通知关闭。
JPushPlugin.prototype.getUserNotificationSettings = function(callback) {
if(this.isPlatformIOS()) {
this.call_native("getUserNotificationSettings", [], callback);
} else if (device.platform == "Android") {
this.call_native("areNotificationEnabled", [], callback);
}
JPushPlugin.prototype.getUserNotificationSettings = function (callback) {
if (this.isPlatformIOS()) {
this.call_native('getUserNotificationSettings', [], callback)
} else if (device.platform == 'Android') {
this.call_native('areNotificationEnabled', [], callback)
}
}
// Android methods
JPushPlugin.prototype.setDebugMode = function(mode) {
if(device.platform == "Android") {
this.call_native("setDebugMode", [mode], null);
}
JPushPlugin.prototype.setDebugMode = function (mode) {
if (device.platform == 'Android') {
this.call_native('setDebugMode', [mode], null)
}
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function() {
if(device.platform == "Android") {
data = [];
this.call_native("setBasicPushNotificationBuilder", data, null);
}
JPushPlugin.prototype.setBasicPushNotificationBuilder = function () {
if (device.platform == 'Android') {
data = []
this.call_native('setBasicPushNotificationBuilder', data, null)
}
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function() {
if(device.platform == "Android") {
data = [];
this.call_native("setCustomPushNotificationBuilder", data, null);
}
JPushPlugin.prototype.setCustomPushNotificationBuilder = function () {
if (device.platform == 'Android') {
data = []
this.call_native('setCustomPushNotificationBuilder', data, null)
}
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function(data) {
try {
console.log("JPushPlugin:receiveMessageInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.receiveMessage = bToObj
cordova.fireDocumentEvent('jpush.receiveMessage', null);
} catch(exception) {
console.log("JPushPlugin:pushCallback " + exception);
}
JPushPlugin.prototype.receiveMessageInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveMessageInAndroidCallback: ' + data)
this.receiveMessage = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveMessage', this.receiveMessage)
} catch(exception) {
console.log('JPushPlugin:pushCallback ' + exception)
}
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function(data) {
try {
console.log("JPushPlugin:openNotificationInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.openNotification = bToObj;
cordova.fireDocumentEvent('jpush.openNotification', null);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.openNotificationInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:openNotificationInAndroidCallback: ' + data)
this.openNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.openNotification', this.openNotification)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function(data) {
try{
console.log("JPushPlugin:receiveNotificationInAndroidCallback");
data = JSON.stringify(data);
var bToObj = JSON.parse(data);
this.receiveNotification = bToObj;
cordova.fireDocumentEvent('jpush.receiveNotification', null);
} catch(exception) {
console.log(exception);
}
JPushPlugin.prototype.receiveNotificationInAndroidCallback = function (data) {
try {
data = JSON.stringify(data)
console.log('JPushPlugin:receiveNotificationInAndroidCallback: ' + data)
this.receiveNotification = JSON.parse(data)
cordova.fireDocumentEvent('jpush.receiveNotification', this.receiveNotification)
} catch(exception) {
console.log(exception)
}
}
JPushPlugin.prototype.clearAllNotification = function() {
if(device.platform == "Android") {
data = [];
this.call_native("clearAllNotification", data, null);
}
JPushPlugin.prototype.clearAllNotification = function () {
if (device.platform == 'Android') {
data = []
this.call_native('clearAllNotification', data, null)
}
}
JPushPlugin.prototype.clearNotificationById = function(notificationId) {
if(device.platform == "Android") {
data = [];
this.call_native("clearNotificationById", [notificationId], null);
}
JPushPlugin.prototype.clearNotificationById = function (notificationId) {
if (device.platform == 'Android') {
data = []
this.call_native('clearNotificationById', [notificationId], null)
}
}
JPushPlugin.prototype.setLatestNotificationNum = function(num) {
if(device.platform == "Android") {
this.call_native("setLatestNotificationNum", [num], null);
}
JPushPlugin.prototype.setLatestNotificationNum = function (num) {
if (device.platform == 'Android') {
this.call_native('setLatestNotificationNum', [num], null)
}
}
JPushPlugin.prototype.setDebugMode = function(mode) {
if(device.platform == "Android") {
this.call_native("setDebugMode", [mode], null);
}
JPushPlugin.prototype.setDebugMode = function (mode) {
if (device.platform == 'Android') {
this.call_native('setDebugMode', [mode], null)
}
}
JPushPlugin.prototype.addLocalNotification = function(builderId, content, title,
notificationID, broadcastTime, extras) {
if(device.platform == "Android") {
data = [builderId, content, title, notificationID, broadcastTime, extras];
this.call_native("addLocalNotification", data, null);
}
JPushPlugin.prototype.addLocalNotification = function (builderId, content, title,
notificationID, broadcastTime, extras) {
if (device.platform == 'Android') {
data = [builderId, content, title, notificationID, broadcastTime, extras]
this.call_native('addLocalNotification', data, null)
}
}
JPushPlugin.prototype.removeLocalNotification = function(notificationID) {
if(device.platform == "Android") {
this.call_native("removeLocalNotification", [notificationID], null);
}
JPushPlugin.prototype.removeLocalNotification = function (notificationID) {
if (device.platform == 'Android') {
this.call_native('removeLocalNotification', [notificationID], null)
}
}
JPushPlugin.prototype.clearLocalNotifications = function() {
if(device.platform == "Android") {
data = [];
this.call_native("clearLocalNotifications", data, null);
}
JPushPlugin.prototype.clearLocalNotifications = function () {
if (device.platform == 'Android') {
data = []
this.call_native('clearLocalNotifications', data, null)
}
}
JPushPlugin.prototype.reportNotificationOpened = function(msgID) {
if(device.platform == "Android") {
this.call_native("reportNotificationOpened", [msgID], null);
}
JPushPlugin.prototype.reportNotificationOpened = function (msgID) {
if (device.platform == 'Android') {
this.call_native('reportNotificationOpened', [msgID], null)
}
}
/**
*是否开启统计分析功能,用于“用户使用时长”,“活跃用户”,“用户打开次数”的统计,并上报到服务器上,
*在 Portal 上展示给开发者。
*/
JPushPlugin.prototype.setStatisticsOpen = function(mode) {
if(device.platform == "Android") {
this.call_native("setStatisticsOpen", [mode], null);
}
JPushPlugin.prototype.setStatisticsOpen = function (mode) {
if (device.platform == 'Android') {
this.call_native('setStatisticsOpen', [mode], null)
}
}
/**
* 用于在 Android 6.0 及以上系统,申请一些权限
* 具体可看http://docs.jpush.io/client/android_api/#android-60
*/
JPushPlugin.prototype.requestPermission = function() {
if(device.platform == "Android") {
this.call_native("requestPermission", [], null);
}
JPushPlugin.prototype.requestPermission = function () {
if (device.platform == 'Android') {
this.call_native('requestPermission', [], null)
}
}
JPushPlugin.prototype.setSilenceTime = function(startHour, startMinute, endHour, endMinute) {
if (device.platform == "Android") {
this.call_native("setSilenceTime", [startHour, startMinute, endHour, endMinute], null);
}
JPushPlugin.prototype.setSilenceTime = function (startHour, startMinute, endHour, endMinute) {
if (device.platform == 'Android') {
this.call_native('setSilenceTime', [startHour, startMinute, endHour, endMinute], null)
}
}
JPushPlugin.prototype.setPushTime = function(weekdays, startHour, endHour) {
if (device.platform == "Android") {
this.call_native("setPushTime", [weekdays, startHour, endHour], null);
}
JPushPlugin.prototype.setPushTime = function (weekdays, startHour, endHour) {
if (device.platform == 'Android') {
this.call_native('setPushTime', [weekdays, startHour, endHour], null)
}
}
if(!window.plugins) {
window.plugins = {};
if (!window.plugins) {
window.plugins = {}
}
if(!window.plugins.jPushPlugin) {
window.plugins.jPushPlugin = new JPushPlugin();
if (!window.plugins.jPushPlugin) {
window.plugins.jPushPlugin = new JPushPlugin()
}
module.exports = new JPushPlugin();
module.exports = new JPushPlugin()