|
12 | 12 | import io.flutter.plugin.common.MethodChannel;
|
13 | 13 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
14 | 14 | import io.flutter.plugin.common.MethodChannel.Result;
|
| 15 | +import io.flutter.plugin.common.PluginRegistry; |
15 | 16 | import io.flutter.plugin.common.PluginRegistry.Registrar;
|
16 | 17 |
|
17 | 18 | import java.util.ArrayList;
|
|
23 | 24 | import java.util.Set;
|
24 | 25 |
|
25 | 26 | import cn.jpush.android.api.JPushInterface;
|
| 27 | +import io.flutter.view.FlutterNativeView; |
26 | 28 |
|
27 | 29 | /** JPushPlugin */
|
28 | 30 | public class JPushPlugin implements MethodCallHandler {
|
| 31 | + |
29 | 32 | /** Plugin registration. */
|
30 | 33 | public static void registerWith(Registrar registrar) {
|
31 | 34 | final MethodChannel channel = new MethodChannel(registrar.messenger(), "jpush");
|
32 | 35 | channel.setMethodCallHandler(new JPushPlugin(registrar, channel));
|
33 |
| - |
| 36 | + |
| 37 | + registrar.addViewDestroyListener(new PluginRegistry.ViewDestroyListener() { |
| 38 | + @Override |
| 39 | + public boolean onViewDestroy(FlutterNativeView flutterNativeView) { |
| 40 | + instance.dartIsReady = false; |
| 41 | + return false; |
| 42 | + } |
| 43 | + }); |
34 | 44 | }
|
35 | 45 |
|
36 |
| - private static String TAG = "| JPUSH | Android | "; |
| 46 | + private static String TAG = "| JPUSH | Flutter | Android | "; |
37 | 47 | public static JPushPlugin instance;
|
38 | 48 | static List<Map<String, Object>> openNotificationCache = new ArrayList<>();
|
39 | 49 |
|
@@ -86,6 +96,8 @@ public void onMethodCall(MethodCall call, Result result) {
|
86 | 96 | resumePush(call, result);
|
87 | 97 | } else if (call.method.equals("clearAllNotifications")) {
|
88 | 98 | clearAllNotifications(call, result);
|
| 99 | + } else if (call.method.equals("clearNotification")) { |
| 100 | + clearNotification(call,result); |
89 | 101 | } else if (call.method.equals("getLaunchAppNotification")) {
|
90 | 102 | getLaunchAppNotification(call, result);
|
91 | 103 | } else if (call.method.equals("getRegistrationID")) {
|
@@ -133,6 +145,7 @@ public void scheduleCache() {
|
133 | 145 | if (ridAvailable && dartIsReady) {
|
134 | 146 | // try to schedule get rid cache
|
135 | 147 | for (Result res: JPushPlugin.instance.getRidCache) {
|
| 148 | + Log.d(TAG,"scheduleCache rid = " + rid); |
136 | 149 | res.success(rid);
|
137 | 150 | JPushPlugin.instance.getRidCache.remove(res);
|
138 | 151 | }
|
@@ -220,6 +233,13 @@ public void clearAllNotifications(MethodCall call, Result result) {
|
220 | 233 |
|
221 | 234 | JPushInterface.clearAllNotifications(registrar.context());
|
222 | 235 | }
|
| 236 | + public void clearNotification(MethodCall call, Result result) { |
| 237 | + Log.d(TAG,"clearNotification: "); |
| 238 | + Object id = call.arguments; |
| 239 | + if (id != null) { |
| 240 | + JPushInterface.clearNotificationById(registrar.context(),(int)id); |
| 241 | + } |
| 242 | + } |
223 | 243 |
|
224 | 244 | public void getLaunchAppNotification(MethodCall call, Result result) {
|
225 | 245 | Log.d(TAG,"");
|
|
0 commit comments