|
|
@ -9,14 +9,6 @@ import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.jpush.android.data.JPushLocalNotification;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodCall;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel.Result;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.PluginRegistry;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
@ -26,27 +18,23 @@ import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.jpush.android.api.JPushInterface;
|
|
|
|
import cn.jpush.android.api.JPushInterface;
|
|
|
|
import io.flutter.view.FlutterNativeView;
|
|
|
|
import cn.jpush.android.data.JPushLocalNotification;
|
|
|
|
|
|
|
|
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodCall;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
|
|
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel.Result;
|
|
|
|
|
|
|
|
|
|
|
|
/** JPushPlugin */
|
|
|
|
/**
|
|
|
|
public class JPushPlugin implements MethodCallHandler {
|
|
|
|
* JPushPlugin
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class JPushPlugin implements FlutterPlugin, MethodCallHandler {
|
|
|
|
|
|
|
|
|
|
|
|
/** Plugin registration. */
|
|
|
|
|
|
|
|
public static void registerWith(Registrar registrar) {
|
|
|
|
|
|
|
|
final MethodChannel channel = new MethodChannel(registrar.messenger(), "jpush");
|
|
|
|
|
|
|
|
channel.setMethodCallHandler(new JPushPlugin(registrar, channel));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
registrar.addViewDestroyListener(new PluginRegistry.ViewDestroyListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onViewDestroy(FlutterNativeView flutterNativeView) {
|
|
|
|
|
|
|
|
instance.dartIsReady = false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String TAG = "| JPUSH | Flutter | Android | ";
|
|
|
|
private static String TAG = "| JPUSH | Flutter | Android | ";
|
|
|
|
|
|
|
|
|
|
|
|
public static JPushPlugin instance;
|
|
|
|
public static JPushPlugin instance;
|
|
|
|
|
|
|
|
|
|
|
|
static List<Map<String, Object>> openNotificationCache = new ArrayList<>();
|
|
|
|
static List<Map<String, Object>> openNotificationCache = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
private boolean dartIsReady = false;
|
|
|
|
private boolean dartIsReady = false;
|
|
|
@ -54,23 +42,33 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
|
|
|
|
|
|
|
|
private List<Result> getRidCache;
|
|
|
|
private List<Result> getRidCache;
|
|
|
|
|
|
|
|
|
|
|
|
private final Registrar registrar;
|
|
|
|
private Context context;
|
|
|
|
private final MethodChannel channel;
|
|
|
|
private MethodChannel channel;
|
|
|
|
public final Map<Integer, Result> callbackMap;
|
|
|
|
public Map<Integer, Result> callbackMap;
|
|
|
|
private int sequence;
|
|
|
|
private int sequence;
|
|
|
|
|
|
|
|
|
|
|
|
private JPushPlugin(Registrar registrar, MethodChannel channel) {
|
|
|
|
public JPushPlugin() {
|
|
|
|
|
|
|
|
|
|
|
|
this.registrar = registrar;
|
|
|
|
|
|
|
|
this.channel = channel;
|
|
|
|
|
|
|
|
this.callbackMap = new HashMap<>();
|
|
|
|
this.callbackMap = new HashMap<>();
|
|
|
|
this.sequence = 0;
|
|
|
|
this.sequence = 0;
|
|
|
|
this.getRidCache = new ArrayList<>();
|
|
|
|
this.getRidCache = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
instance = this;
|
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
|
|
|
|
|
|
|
|
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "jpush");
|
|
|
|
|
|
|
|
channel.setMethodCallHandler(this);
|
|
|
|
|
|
|
|
context = flutterPluginBinding.getApplicationContext();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onDetachedFromEngine(FlutterPluginBinding binding) {
|
|
|
|
|
|
|
|
channel.setMethodCallHandler(null);
|
|
|
|
|
|
|
|
instance.dartIsReady = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onMethodCall(MethodCall call, Result result) {
|
|
|
|
public void onMethodCall(MethodCall call, Result result) {
|
|
|
|
Log.i(TAG, call.method);
|
|
|
|
Log.i(TAG, call.method);
|
|
|
@ -91,7 +89,8 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
} else if (call.method.equals("setAlias")) {
|
|
|
|
} else if (call.method.equals("setAlias")) {
|
|
|
|
setAlias(call, result);
|
|
|
|
setAlias(call, result);
|
|
|
|
} else if (call.method.equals("deleteAlias")) {
|
|
|
|
} else if (call.method.equals("deleteAlias")) {
|
|
|
|
deleteAlias(call, result);;
|
|
|
|
deleteAlias(call, result);
|
|
|
|
|
|
|
|
;
|
|
|
|
} else if (call.method.equals("stopPush")) {
|
|
|
|
} else if (call.method.equals("stopPush")) {
|
|
|
|
stopPush(call, result);
|
|
|
|
stopPush(call, result);
|
|
|
|
} else if (call.method.equals("resumePush")) {
|
|
|
|
} else if (call.method.equals("resumePush")) {
|
|
|
@ -112,8 +111,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
isNotificationEnabled(call, result);
|
|
|
|
isNotificationEnabled(call, result);
|
|
|
|
} else if (call.method.equals("openSettingsForNotification")) {
|
|
|
|
} else if (call.method.equals("openSettingsForNotification")) {
|
|
|
|
openSettingsForNotification(call, result);
|
|
|
|
openSettingsForNotification(call, result);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
result.notImplemented();
|
|
|
|
result.notImplemented();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -141,10 +139,10 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
boolean debug = (boolean) map.get("debug");
|
|
|
|
boolean debug = (boolean) map.get("debug");
|
|
|
|
JPushInterface.setDebugMode(debug);
|
|
|
|
JPushInterface.setDebugMode(debug);
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.init(registrar.context()); // 初始化 JPush
|
|
|
|
JPushInterface.init(context); // 初始化 JPush
|
|
|
|
|
|
|
|
|
|
|
|
String channel = (String) map.get("channel");
|
|
|
|
String channel = (String) map.get("channel");
|
|
|
|
JPushInterface.setChannel(registrar.context(), channel);
|
|
|
|
JPushInterface.setChannel(context, channel);
|
|
|
|
|
|
|
|
|
|
|
|
JPushPlugin.instance.dartIsReady = true;
|
|
|
|
JPushPlugin.instance.dartIsReady = true;
|
|
|
|
|
|
|
|
|
|
|
@ -167,12 +165,12 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
openNotificationCacheList.removeAll(tempList);
|
|
|
|
openNotificationCacheList.removeAll(tempList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (registrar == null || registrar.context() == null) {
|
|
|
|
if (context == null) {
|
|
|
|
Log.d(TAG, "scheduleCache,register context is nil.");
|
|
|
|
Log.d(TAG, "scheduleCache,register context is nil.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String rid = JPushInterface.getRegistrationID(registrar.context());
|
|
|
|
String rid = JPushInterface.getRegistrationID(context);
|
|
|
|
boolean ridAvailable = rid != null && !rid.isEmpty();
|
|
|
|
boolean ridAvailable = rid != null && !rid.isEmpty();
|
|
|
|
if (ridAvailable && dartIsReady) {
|
|
|
|
if (ridAvailable && dartIsReady) {
|
|
|
|
// try to schedule get rid cache
|
|
|
|
// try to schedule get rid cache
|
|
|
@ -194,7 +192,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.setTags(registrar.context(), sequence, tags);
|
|
|
|
JPushInterface.setTags(context, sequence, tags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void cleanTags(MethodCall call, Result result) {
|
|
|
|
public void cleanTags(MethodCall call, Result result) {
|
|
|
@ -202,7 +200,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
|
|
|
|
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.cleanTags(registrar.context(), sequence);
|
|
|
|
JPushInterface.cleanTags(context, sequence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void addTags(MethodCall call, Result result) {
|
|
|
|
public void addTags(MethodCall call, Result result) {
|
|
|
@ -212,7 +210,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.addTags(registrar.context(), sequence, tags);
|
|
|
|
JPushInterface.addTags(context, sequence, tags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteTags(MethodCall call, Result result) {
|
|
|
|
public void deleteTags(MethodCall call, Result result) {
|
|
|
@ -222,7 +220,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
Set<String> tags = new HashSet<>(tagList);
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.deleteTags(registrar.context(), sequence, tags);
|
|
|
|
JPushInterface.deleteTags(context, sequence, tags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void getAllTags(MethodCall call, Result result) {
|
|
|
|
public void getAllTags(MethodCall call, Result result) {
|
|
|
@ -230,7 +228,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
|
|
|
|
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.getAllTags(registrar.context(), sequence);
|
|
|
|
JPushInterface.getAllTags(context, sequence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setAlias(MethodCall call, Result result) {
|
|
|
|
public void setAlias(MethodCall call, Result result) {
|
|
|
@ -239,7 +237,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
String alias = call.arguments();
|
|
|
|
String alias = call.arguments();
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.setAlias(registrar.context(), sequence, alias);
|
|
|
|
JPushInterface.setAlias(context, sequence, alias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void deleteAlias(MethodCall call, Result result) {
|
|
|
|
public void deleteAlias(MethodCall call, Result result) {
|
|
|
@ -248,31 +246,32 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
String alias = call.arguments();
|
|
|
|
String alias = call.arguments();
|
|
|
|
sequence += 1;
|
|
|
|
sequence += 1;
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
callbackMap.put(sequence, result);
|
|
|
|
JPushInterface.deleteAlias(registrar.context(), sequence);
|
|
|
|
JPushInterface.deleteAlias(context, sequence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void stopPush(MethodCall call, Result result) {
|
|
|
|
public void stopPush(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "stopPush:");
|
|
|
|
Log.d(TAG, "stopPush:");
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.stopPush(registrar.context());
|
|
|
|
JPushInterface.stopPush(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void resumePush(MethodCall call, Result result) {
|
|
|
|
public void resumePush(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "resumePush:");
|
|
|
|
Log.d(TAG, "resumePush:");
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.resumePush(registrar.context());
|
|
|
|
JPushInterface.resumePush(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clearAllNotifications(MethodCall call, Result result) {
|
|
|
|
public void clearAllNotifications(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "clearAllNotifications: ");
|
|
|
|
Log.d(TAG, "clearAllNotifications: ");
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.clearAllNotifications(registrar.context());
|
|
|
|
JPushInterface.clearAllNotifications(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clearNotification(MethodCall call, Result result) {
|
|
|
|
public void clearNotification(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "clearNotification: ");
|
|
|
|
Log.d(TAG, "clearNotification: ");
|
|
|
|
Object id = call.arguments;
|
|
|
|
Object id = call.arguments;
|
|
|
|
if (id != null) {
|
|
|
|
if (id != null) {
|
|
|
|
JPushInterface.clearNotificationById(registrar.context(),(int)id);
|
|
|
|
JPushInterface.clearNotificationById(context, (int) id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -285,12 +284,12 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
public void getRegistrationID(MethodCall call, Result result) {
|
|
|
|
public void getRegistrationID(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "getRegistrationID: ");
|
|
|
|
Log.d(TAG, "getRegistrationID: ");
|
|
|
|
|
|
|
|
|
|
|
|
if (registrar == null || registrar.context() == null) {
|
|
|
|
if (context == null) {
|
|
|
|
Log.d(TAG, "register context is nil.");
|
|
|
|
Log.d(TAG, "register context is nil.");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String rid = JPushInterface.getRegistrationID(registrar.context());
|
|
|
|
String rid = JPushInterface.getRegistrationID(context);
|
|
|
|
if (rid == null || rid.isEmpty()) {
|
|
|
|
if (rid == null || rid.isEmpty()) {
|
|
|
|
getRidCache.add(result);
|
|
|
|
getRidCache.add(result);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -320,7 +319,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
long date = (long) map.get("fireTime");
|
|
|
|
long date = (long) map.get("fireTime");
|
|
|
|
ln.setBroadcastTime(date);
|
|
|
|
ln.setBroadcastTime(date);
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.addLocalNotification(registrar.context(), ln);
|
|
|
|
JPushInterface.addLocalNotification(context, ln);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -333,7 +332,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
Object numObject = map.get("badge");
|
|
|
|
Object numObject = map.get("badge");
|
|
|
|
if (numObject != null) {
|
|
|
|
if (numObject != null) {
|
|
|
|
int num = (int) numObject;
|
|
|
|
int num = (int) numObject;
|
|
|
|
JPushInterface.setBadgeNumber(registrar.context(),num);
|
|
|
|
JPushInterface.setBadgeNumber(context, num);
|
|
|
|
result.success(true);
|
|
|
|
result.success(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -341,7 +340,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
/// 检查当前应用的通知开关是否开启
|
|
|
|
/// 检查当前应用的通知开关是否开启
|
|
|
|
private void isNotificationEnabled(MethodCall call, Result result) {
|
|
|
|
private void isNotificationEnabled(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "isNotificationEnabled: ");
|
|
|
|
Log.d(TAG, "isNotificationEnabled: ");
|
|
|
|
int isEnabled = JPushInterface.isNotificationEnabled(registrar.context());
|
|
|
|
int isEnabled = JPushInterface.isNotificationEnabled(context);
|
|
|
|
//1表示开启,0表示关闭,-1表示检测失败
|
|
|
|
//1表示开启,0表示关闭,-1表示检测失败
|
|
|
|
HashMap<String, Object> map = new HashMap();
|
|
|
|
HashMap<String, Object> map = new HashMap();
|
|
|
|
map.put("isEnabled", isEnabled == 1 ? true : false);
|
|
|
|
map.put("isEnabled", isEnabled == 1 ? true : false);
|
|
|
@ -352,7 +351,7 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
private void openSettingsForNotification(MethodCall call, Result result) {
|
|
|
|
private void openSettingsForNotification(MethodCall call, Result result) {
|
|
|
|
Log.d(TAG, "openSettingsForNotification: ");
|
|
|
|
Log.d(TAG, "openSettingsForNotification: ");
|
|
|
|
|
|
|
|
|
|
|
|
JPushInterface.goToAppNotificationSettings(registrar.context());
|
|
|
|
JPushInterface.goToAppNotificationSettings(context);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -369,7 +368,6 @@ public class JPushPlugin implements MethodCallHandler {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
String action = intent.getAction();
|
|
|
|