mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-01-31 14:32:51 +08:00
update doc & add some new features
支持安卓直接获得通知标题; 优化安卓获取附加字段的方法。
This commit is contained in:
parent
1ff72e4df4
commit
dfb883e24c
@ -63,14 +63,14 @@ JPush-PhoneGap-Plugin 支持 iOS, Android 的推送插件。
|
||||
window.plugins.jPushPlugin.init();
|
||||
|
||||
|
||||
### Android 手工安装
|
||||
### Android 手动安装
|
||||
|
||||
[Android 手工安装文档地址](document/Android_handle_install.md)
|
||||
[Android 手动安装文档地址](document/Android_handle_install.md)
|
||||
|
||||
|
||||
### iOS 手工安装
|
||||
### iOS 手动安装
|
||||
|
||||
[IOS手工安装文档地址](document/iOS_handle_install.md)
|
||||
[IOS手动安装文档地址](document/iOS_handle_install.md)
|
||||
|
||||
|
||||
###示例
|
||||
|
@ -1,13 +1,21 @@
|
||||
#Android 手工安装
|
||||
#Android 手动安装
|
||||
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
1. 复制:`$JPUSH_PLUGIN_DIR`/src/android/*.java 到 cn/jpush/phonega/ 目录下(即:cn.jpush.phonegap 的包下)
|
||||
2. 复制:`$JPUSH_PLUGIN_DIR`/src/android/armeabi/libjpush.so 到 lib/armeabi/
|
||||
3. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush-sdk-release2.0.6.jar 到 lib/
|
||||
4. 复制:`$JPUSH_PLUGIN_DIR`/src/android/test_notification_layout.xml 到 res/layout/
|
||||
5. 复制:`$JPUSH_PLUGIN_DIR`/src/android/jpush_notification_icon.png 到 res/drawable/
|
||||
6. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
1. 复制:$JPUSH_PLUGIN_DIR/src/android/*.java 到 cn/jpush/phonega/ 目录下(即:cn.jpush.phonegap 的包下)
|
||||
2. 复制:$JPUSH_PLUGIN_DIR/src/android/armeabi/libjpush.so 到 lib/armeabi/
|
||||
3. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush-sdk-release2.0.6.jar 到 lib/
|
||||
4. 复制:$JPUSH_PLUGIN_DIR/src/android/test_notification_layout.xml 到 res/layout/
|
||||
5. 复制:$JPUSH_PLUGIN_DIR/src/android/jpush_notification_icon.png 到 res/drawable/
|
||||
6. 复制:$JPUSH_PLUGIN_DIR/www/JPushPlugin.js 到 assets/www/plugins/cn.jpush.phonegap.JPushPlugin.www/
|
||||
和 platform_www/plugins/cn.jpush.phonegap.JPushPlugin/www/
|
||||
并在 JPushPlugin.js 文件的代码外添加:
|
||||
|
||||
cordova.define("cn.jpush.phonegap.JPushPlugin.JPushPlugin", function(require, exports, module) {
|
||||
// 代码
|
||||
});
|
||||
|
||||
7. 修改 AndroidManifest.xml 在 manifest 节点下添加以下权限
|
||||
|
||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE"/>
|
||||
|
@ -1,4 +1,4 @@
|
||||
### iOS手工安装
|
||||
### iOS手动安装
|
||||
|
||||
下载 JPush PhoneGap 插件,并解压缩,标记插件目录为:`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
|
@ -66,7 +66,6 @@
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alertContent);
|
||||
|
||||
} catch (exeption) {
|
||||
console.log(exception)
|
||||
}
|
||||
@ -90,7 +89,6 @@
|
||||
try {
|
||||
window.plugins.jPushPlugin.init();
|
||||
getRegistrationID();
|
||||
|
||||
if (device.platform != "Android") {
|
||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
||||
|
@ -70,8 +70,11 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
private static boolean shouldCacheMsg = false;
|
||||
private static boolean isStatisticsOpened = false; // 是否开启统计分析功能
|
||||
|
||||
public static String notificationTitle;
|
||||
public static String notificationAlert;
|
||||
public static Map<String, Object> notificationExtras = new HashMap<String, Object>();
|
||||
|
||||
public static String openNotificationTitle;
|
||||
public static String openNotificationAlert;
|
||||
public static Map<String, Object> openNotificationExtras = new HashMap<String, Object>();
|
||||
|
||||
@ -93,11 +96,13 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
//这样做是为了和iOS 统一
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.transmitOpen(JPushPlugin.notificationTitle,
|
||||
JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationTitle,
|
||||
JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
}
|
||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||
@ -121,11 +126,13 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
}
|
||||
if (JPushPlugin.openNotificationAlert != null) {
|
||||
JPushPlugin.notificationAlert = null;
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.transmitOpen(JPushPlugin.notificationTitle,
|
||||
JPushPlugin.openNotificationAlert,
|
||||
JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if (JPushPlugin.notificationAlert != null) {
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert,
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationTitle,
|
||||
JPushPlugin.notificationAlert,
|
||||
JPushPlugin.notificationExtras);
|
||||
}
|
||||
}
|
||||
@ -139,6 +146,13 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
String key;
|
||||
Iterator keys = jo.keys();
|
||||
while(keys.hasNext()) {
|
||||
key = keys.next().toString();
|
||||
Log.i(TAG, key);
|
||||
jExtras.put(key, jo.getString(key));
|
||||
}
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
@ -153,15 +167,22 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
return data;
|
||||
}
|
||||
|
||||
private static JSONObject openNotificationObject(String alert,
|
||||
Map<String, Object> extras) {
|
||||
private static JSONObject openNotificationObject(String title,
|
||||
String alert, Map<String, Object> extras) {
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("title", title);
|
||||
data.put("alert", alert);
|
||||
JSONObject jExtras = new JSONObject();
|
||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||
JSONObject jo = new JSONObject((String) entry.getValue());
|
||||
String key;
|
||||
Iterator keys = jo.keys();
|
||||
while(keys.hasNext()) {
|
||||
key = keys.next().toString();
|
||||
jExtras.put(key, jo.getString(key));
|
||||
}
|
||||
jExtras.put("cn.jpush.android.EXTRA", jo);
|
||||
} else {
|
||||
jExtras.put(entry.getKey(), entry.getValue());
|
||||
@ -191,14 +212,14 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
static void transmitOpen(String alert, Map<String, Object> extras) {
|
||||
static void transmitOpen(String title, String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
if (JPushPlugin.shouldCacheMsg) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
JSONObject data = openNotificationObject(title, alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.openNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@ -207,14 +228,15 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.openNotificationTitle = null;
|
||||
JPushPlugin.openNotificationAlert = null;
|
||||
}
|
||||
|
||||
static void transmitReceive(String alert, Map<String, Object> extras) {
|
||||
static void transmitReceive(String title, String alert, Map<String, Object> extras) {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
JSONObject data = openNotificationObject(alert, extras);
|
||||
JSONObject data = openNotificationObject(title, alert, extras);
|
||||
String format = "window.plugins.jPushPlugin.receiveNotificationInAndroidCallback(%s);";
|
||||
final String js = String.format(format, data.toString());
|
||||
cordovaActivity.runOnUiThread(new Runnable() {
|
||||
@ -223,6 +245,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
instance.webView.loadUrl("javascript:" + js);
|
||||
}
|
||||
});
|
||||
JPushPlugin.notificationTitle = null;
|
||||
JPushPlugin.notificationAlert = null;
|
||||
}
|
||||
|
||||
|
@ -44,13 +44,16 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
private void handlingNotificationOpen(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationOpen");
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.openNotificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitOpen(alert, extras);
|
||||
JPushPlugin.transmitOpen(title, alert, extras);
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
@ -62,17 +65,21 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
private void handlingNotificationReceive(Context context, Intent intent) {
|
||||
Log.i(TAG, "---------------- handlingNotificationReceive");
|
||||
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(
|
||||
context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
String title = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
|
||||
JPushPlugin.notificationTitle = title;
|
||||
|
||||
String alert = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
|
||||
JPushPlugin.notificationAlert = alert;
|
||||
|
||||
Map<String, Object> extras = getNotificationExtras(intent);
|
||||
JPushPlugin.notificationExtras = extras;
|
||||
|
||||
JPushPlugin.transmitReceive(alert, extras);
|
||||
JPushPlugin.transmitReceive(title, alert, extras);
|
||||
}
|
||||
|
||||
private Map<String, Object> getNotificationExtras(Intent intent) {
|
||||
|
Loading…
Reference in New Issue
Block a user