android: ExtensionApiModule支持callback fail

master
zhongweiguang 2021-08-20 15:53:39 +08:00
parent 215991eab0
commit 28a088c33f
1 changed files with 19 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import android.os.Looper;
import android.util.Log;
import com.finogeeks.lib.applet.client.FinAppClient;
import com.finogeeks.lib.applet.client.FinAppTrace;
import com.finogeeks.mop.api.BaseApi;
import com.finogeeks.mop.interfaces.ICallback;
import com.finogeeks.mop.service.MopPluginService;
@ -22,6 +23,8 @@ import io.flutter.plugin.common.MethodChannel;
public class ExtensionApiModule extends BaseApi {
private static final String TAG = "ExtensionApiModule";
private Handler handler = new Handler(Looper.getMainLooper());
public ExtensionApiModule(Context context) {
@ -52,18 +55,33 @@ public class ExtensionApiModule extends BaseApi {
@Override
public void success(Object result) {
String json = GsonUtil.gson.toJson(result);
FinAppTrace.d(ExtensionApiModule.TAG, "channel invokeMethod:" + name
+ " success, result=" + result + ", json=" + json);
JSONObject ret = null;
if (json != null && !json.equals("null"))
if (json != null && !json.equals("null")) {
try {
ret = new JSONObject(json);
if (ret.has("errMsg")) {
String errMsg = ret.getString("errMsg");
if (errMsg.startsWith(name + ":fail")) {
iCallback.onFail(ret);
return;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
iCallback.onSuccess(ret);
}
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
FinAppTrace.e(ExtensionApiModule.TAG, "channel invokeMethod:" + name
+ " error, errorCode=" + errorCode
+ ", errorMessage=" + errorMessage
+ ", errorDetails=" + errorDetails);
iCallback.onFail();
}