fix:Android端新增将正在运行的最后一个打开的小程序移至前台的方法;

master
yangbingqiao 2022-10-10 11:46:30 +08:00
parent ffbc1b16d7
commit 373bbdbe42
4 changed files with 59 additions and 26 deletions

View File

@ -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<String, String> resultMap = (Map<String, String>) 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();
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<Object> 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);
}
}
}
}

View File

@ -675,4 +675,11 @@ class Mop {
_webExtensionApis[name] = handler;
_channel.invokeMethod("addWebExtentionApi", {"name": name});
}
///
///
///
void moveCurrentAppletToFront() async {
return await _channel.invokeMethod("moveCurrentAppletToFront");
}
}