我使用Flutter调用Android第三方SDK,但我不知道如何从Flutter的onCallback()
方法中获取值'i'和'info'。
代码
public static void registerWith(PluginRegistry.Registrar registrar) {
channel = new MethodChannel(registrar.messenger(), CHANNEL);
LivenessPlug instance = new LivenessPlug(registrar.activity());
channel.setMethodCallHandler(instance);
}
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("getLivenessResult")) {
try {
getLivenessResult();
result.success();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, e.toString(), 2000).show();
}
}
else {
result.notImplemented();
}
}
public void getLivenessResult() {
OctopusLivenessManager.getInstance().
detectLiveness(activity, new OctopusLivenessCallback() {
@Override
public void onCallback(int i, OctopusLivenessInfo info) {
if (i == 0) {
Log.e("result", info.verificationPackage);
}
Toast.makeText(activity, i + "", Toast.LENGTH_SHORT).show();
}
});
}
}
最佳答案
@SuppressLint("WrongConstant")
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.equals("getLivenessResult")) {
try {
getLivenessResult();
result.success();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, e.toString(), 2000).show();
}
}
else {
result.notImplemented();
}
}
关于java - 如何让Android返回一个内部类对象给flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59469916/