From 373bbdbe42537e5ff605cd2e540a8529f6d7de7d Mon Sep 17 00:00:00 2001 From: yangbingqiao Date: Mon, 10 Oct 2022 11:46:30 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9AAndroid=E7=AB=AF=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=B0=86=E6=AD=A3=E5=9C=A8=E8=BF=90=E8=A1=8C=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E4=B8=AA=E6=89=93=E5=BC=80=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=A7=BB=E8=87=B3=E5=89=8D=E5=8F=B0=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mop/api/mop/AppletHandlerModule.java | 27 ++---------- .../mop/api/mop/AppletManageModule.java | 8 +++- .../com/finogeeks/mop/utils/AppletUtils.java | 43 +++++++++++++++++++ lib/mop.dart | 7 +++ 4 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 android/src/main/java/com/finogeeks/mop/utils/AppletUtils.java diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java index 76237b4..e58f2b0 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletHandlerModule.java @@ -23,6 +23,7 @@ import com.finogeeks.lib.applet.sdk.api.IAppletHandler; import com.finogeeks.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; import com.finogeeks.mop.service.MopPluginService; +import com.finogeeks.mop.utils.AppletUtils; import com.finogeeks.mop.utils.GsonUtil; import com.google.gson.reflect.TypeToken; @@ -374,7 +375,7 @@ public class AppletHandlerModule extends BaseApi { channel.invokeMethod(channelMethodName, null, new MethodChannel.Result() { @Override public void success(@androidx.annotation.Nullable Object result) { - moveCurrentAppletToFront(); + AppletUtils.moveCurrentAppletToFront(getContext(), null); if (result != null) { try { Map resultMap = (Map) result; @@ -393,7 +394,7 @@ public class AppletHandlerModule extends BaseApi { @Override public void error(String errorCode, @androidx.annotation.Nullable String errorMessage, @androidx.annotation.Nullable Object errorDetails) { - moveCurrentAppletToFront(); + AppletUtils.moveCurrentAppletToFront(getContext(), null); callback.onFailure(); } @@ -404,26 +405,4 @@ public class AppletHandlerModule extends BaseApi { }); }); } - - private void moveCurrentAppletToFront() { - try { - String currentAppletId = FinAppClient.INSTANCE.getAppletApiManager().getCurrentAppletId(); - if (currentAppletId == null || TextUtils.isEmpty(currentAppletId)) { - return; - } - String activityName = FinAppClient.INSTANCE.getAppletApiManager().getAppletActivityName(currentAppletId); - if (activityName == null) { - return; - } - if (activityName.contains("@")) { - activityName = activityName.substring(0, activityName.indexOf("@")); - } - Intent intent = new Intent(getContext(), Class.forName(activityName)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - PendingIntent pendingIntent = PendingIntent.getActivities(getContext(), 0, new Intent[]{intent}, 0); - pendingIntent.send(); - } catch (Exception e) { - e.printStackTrace(); - } - } } diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java index d950b9a..c9e23fa 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java @@ -15,6 +15,7 @@ import com.finogeeks.lib.applet.interfaces.FinCallback; import com.finogeeks.lib.applet.rest.model.WechatLoginInfo; import com.finogeeks.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; +import com.finogeeks.mop.utils.AppletUtils; import com.google.gson.Gson; import java.util.HashMap; @@ -32,8 +33,9 @@ public class AppletManageModule extends BaseApi { @Override public String[] apis() { return new String[]{"currentApplet", "closeAllApplets", "clearApplets", - "removeUsedApplet", "removeAllUsedApplets","closeApplet", - "setActivityTransitionAnim", "sendCustomEvent", "callJS", "finishRunningApplet"}; + "removeUsedApplet", "removeAllUsedApplets", "closeApplet", + "setActivityTransitionAnim", "sendCustomEvent", "callJS", "finishRunningApplet", + "moveCurrentAppletToFront"}; } @Override @@ -168,6 +170,8 @@ public class AppletManageModule extends BaseApi { } else { callback.onFail(null); } + } else if (event.equals("moveCurrentAppletToFront")) { + AppletUtils.moveCurrentAppletToFront(getContext(), callback); } } } diff --git a/android/src/main/java/com/finogeeks/mop/utils/AppletUtils.java b/android/src/main/java/com/finogeeks/mop/utils/AppletUtils.java new file mode 100644 index 0000000..8c3d6ab --- /dev/null +++ b/android/src/main/java/com/finogeeks/mop/utils/AppletUtils.java @@ -0,0 +1,43 @@ +package com.finogeeks.mop.utils; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.text.TextUtils; + +import com.finogeeks.lib.applet.client.FinAppClient; +import com.finogeeks.mop.interfaces.ICallback; + +public class AppletUtils { + public static void moveCurrentAppletToFront(Context context, ICallback callback) { + try { + String currentAppletId = FinAppClient.INSTANCE.getAppletApiManager().getCurrentAppletId(); + if (currentAppletId == null || TextUtils.isEmpty(currentAppletId)) { + if (callback != null) { + callback.onFail(null); + } + return; + } + String activityName = FinAppClient.INSTANCE.getAppletApiManager().getAppletActivityName(currentAppletId); + if (activityName == null) { + if (callback != null) { + callback.onFail(null); + } + return; + } + if (activityName.contains("@")) { + activityName = activityName.substring(0, activityName.indexOf("@")); + } + Intent intent = new Intent(context, Class.forName(activityName)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + PendingIntent pendingIntent = PendingIntent.getActivities(context, 0, new Intent[]{intent}, 0); + pendingIntent.send(); + callback.onSuccess(null); + } catch (Exception e) { + e.printStackTrace(); + if (callback != null) { + callback.onFail(null); + } + } + } +} diff --git a/lib/mop.dart b/lib/mop.dart index 7bd54a8..dd61dc4 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -675,4 +675,11 @@ class Mop { _webExtensionApis[name] = handler; _channel.invokeMethod("addWebExtentionApi", {"name": name}); } + + /// + /// 将当前正在运行的最后一个打开的小程序移至任务栈前台 + /// + void moveCurrentAppletToFront() async { + return await _channel.invokeMethod("moveCurrentAppletToFront"); + } }