android: ExtensionApiModule支持callback fail
parent
215991eab0
commit
28a088c33f
|
@ -6,6 +6,7 @@ import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||||
|
import com.finogeeks.lib.applet.client.FinAppTrace;
|
||||||
import com.finogeeks.mop.api.BaseApi;
|
import com.finogeeks.mop.api.BaseApi;
|
||||||
import com.finogeeks.mop.interfaces.ICallback;
|
import com.finogeeks.mop.interfaces.ICallback;
|
||||||
import com.finogeeks.mop.service.MopPluginService;
|
import com.finogeeks.mop.service.MopPluginService;
|
||||||
|
@ -22,6 +23,8 @@ import io.flutter.plugin.common.MethodChannel;
|
||||||
|
|
||||||
public class ExtensionApiModule extends BaseApi {
|
public class ExtensionApiModule extends BaseApi {
|
||||||
|
|
||||||
|
private static final String TAG = "ExtensionApiModule";
|
||||||
|
|
||||||
private Handler handler = new Handler(Looper.getMainLooper());
|
private Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
public ExtensionApiModule(Context context) {
|
public ExtensionApiModule(Context context) {
|
||||||
|
@ -52,18 +55,33 @@ public class ExtensionApiModule extends BaseApi {
|
||||||
@Override
|
@Override
|
||||||
public void success(Object result) {
|
public void success(Object result) {
|
||||||
String json = GsonUtil.gson.toJson(result);
|
String json = GsonUtil.gson.toJson(result);
|
||||||
|
FinAppTrace.d(ExtensionApiModule.TAG, "channel invokeMethod:" + name
|
||||||
|
+ " success, result=" + result + ", json=" + json);
|
||||||
JSONObject ret = null;
|
JSONObject ret = null;
|
||||||
if (json != null && !json.equals("null"))
|
if (json != null && !json.equals("null")) {
|
||||||
try {
|
try {
|
||||||
ret = new JSONObject(json);
|
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) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
iCallback.onSuccess(ret);
|
iCallback.onSuccess(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
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();
|
iCallback.onFail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue