mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2025-05-07 11:02:58 +08:00
Update API to don't depend support lib.
This commit is contained in:
parent
673a402c51
commit
5f93fc3f49
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
[](https://travis-ci.org/jpush/jpush-phonegap-plugin)
|
||||||
[]()
|
[]()
|
||||||
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
[](https://github.com/jpush/jpush-phonegap-plugin/releases)
|
||||||
[](https://github.com/jpush/jpush-phonegap-plugin)
|
[](https://github.com/jpush/jpush-phonegap-plugin)
|
||||||
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
[](http://weibo.com/jpush?refer_flag=1001030101_&is_all=1)
|
||||||
|
|
||||||
@ -75,8 +75,6 @@ Cordova CLI 的具体用法可参考 [Cordova CLI 官方文档](https://cordova.
|
|||||||
|
|
||||||
解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
解决方案:Eclipse 中右键单击工程名,Build Path -> Config Build Path -> Projects -> 选中工程名称 -> CordovaLib -> 点击 add。
|
||||||
|
|
||||||
- 最新版插件依赖 android-support-v4:24.0.0 jar 包,需要及时更新 *Android Support Repository*。
|
|
||||||
|
|
||||||
### 2. iOS
|
### 2. iOS
|
||||||
|
|
||||||
- 收不到推送:
|
- 收不到推送:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jpush-phonegap-plugin",
|
"name": "jpush-phonegap-plugin",
|
||||||
"version": "2.2.3",
|
"version": "2.2.4",
|
||||||
"description": "JPush for cordova plugin",
|
"description": "JPush for cordova plugin",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "jpush-phonegap-plugin",
|
"id": "jpush-phonegap-plugin",
|
||||||
|
@ -58,8 +58,6 @@
|
|||||||
</feature>
|
</feature>
|
||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<framework src="com.android.support:support-v4:24.0.0" />
|
|
||||||
|
|
||||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||||
<!-- Required 一些系统要求的权限,如访问网络等-->
|
<!-- Required 一些系统要求的权限,如访问网络等-->
|
||||||
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
|
<uses-permission android:name="$PACKAGE_NAME.permission.JPUSH_MESSAGE" />
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package cn.jpush.phonegap;
|
package cn.jpush.phonegap;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AppOpsManager;
|
||||||
import android.content.Context;
|
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.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -14,6 +17,8 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -180,7 +185,7 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
JSONObject jExtras = new JSONObject();
|
JSONObject jExtras = new JSONObject();
|
||||||
for (Entry<String, Object> entry : extras.entrySet()) {
|
for (Entry<String, Object> entry : extras.entrySet()) {
|
||||||
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
if (entry.getKey().equals("cn.jpush.android.EXTRA")) {
|
||||||
JSONObject jo = null;
|
JSONObject jo;
|
||||||
if (TextUtils.isEmpty((String) entry.getValue())) {
|
if (TextUtils.isEmpty((String) entry.getValue())) {
|
||||||
jo = new JSONObject();
|
jo = new JSONObject();
|
||||||
} else {
|
} else {
|
||||||
@ -314,10 +319,8 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
|
void areNotificationEnabled(JSONArray data, final CallbackContext callback) {
|
||||||
NotificationManagerCompat nmc = NotificationManagerCompat.from(
|
|
||||||
cordova.getActivity().getApplicationContext());
|
|
||||||
int isEnabled;
|
int isEnabled;
|
||||||
if (nmc.areNotificationsEnabled()) {
|
if (hasPermission("OP_POST_NOTIFICATION")) {
|
||||||
isEnabled = 1;
|
isEnabled = 1;
|
||||||
} else {
|
} else {
|
||||||
isEnabled = 0;
|
isEnabled = 0;
|
||||||
@ -458,14 +461,8 @@ public class JPushPlugin extends CordovaPlugin {
|
|||||||
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
// CustomPushNotificationBuilder builder = new CustomPushNotificationBuilder(
|
||||||
// this.cordova.getActivity(), R.layout.test_notification_layout,
|
// this.cordova.getActivity(), R.layout.test_notification_layout,
|
||||||
// R.id.icon, R.id.title, R.id.text);
|
// R.id.icon, R.id.title, R.id.text);
|
||||||
// builder.developerArg0 = "Custom Builder 1";
|
|
||||||
// JPushInterface.setPushNotificationBuilder(2, builder);
|
// JPushInterface.setPushNotificationBuilder(2, builder);
|
||||||
// JSONObject obj = new JSONObject();
|
// JPushInterface.setDefaultPushNotificationBuilder(builder);
|
||||||
// try {
|
|
||||||
// obj.put("id", 2);
|
|
||||||
// } catch (JSONException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearAllNotification(JSONArray data, CallbackContext callbackContext) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user