新增getMobileNumber接口
parent
e75eebb6d8
commit
e1941bd839
|
@ -21,6 +21,7 @@ import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -35,6 +36,8 @@ import io.flutter.plugin.common.MethodChannel;
|
||||||
public class AppletHandlerModule extends BaseApi {
|
public class AppletHandlerModule extends BaseApi {
|
||||||
|
|
||||||
private Handler handler = new Handler(Looper.getMainLooper());
|
private Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
private IAppletHandler.IAppletCallback phoneNumberCallback;
|
||||||
|
private IAppletHandler mIAppletHandler = null;
|
||||||
|
|
||||||
public AppletHandlerModule(Context context) {
|
public AppletHandlerModule(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -42,14 +45,21 @@ public class AppletHandlerModule extends BaseApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] apis() {
|
public String[] apis() {
|
||||||
return new String[]{"registerAppletHandler"};
|
return new String[]{"registerAppletHandler", "getPhoneNumberResult"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String event, Map param, ICallback callback) {
|
public void invoke(String event, Map param, ICallback callback) {
|
||||||
|
|
||||||
|
if ("getPhoneNumberResult".equals(event)) {
|
||||||
|
FinAppTrace.d("AppletHandlerModule", "getPhoneNumberResult");
|
||||||
|
getPhoneNumberResult(event, param, callback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log.d("AppletHandlerModule", "registerAppletHandler");
|
Log.d("AppletHandlerModule", "registerAppletHandler");
|
||||||
|
|
||||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||||
FinAppClient.INSTANCE.getAppletApiManager().setAppletHandler(new IAppletHandler() {
|
FinAppClient.INSTANCE.getAppletApiManager().setAppletHandler(mIAppletHandler = new IAppletHandler() {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
@ -250,6 +260,29 @@ public class AppletHandlerModule extends BaseApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getPhoneNumber(@NotNull IAppletCallback callback) {
|
public void getPhoneNumber(@NotNull IAppletCallback callback) {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
handler.post(() -> {
|
||||||
|
channel.invokeMethod("extensionApi:getPhoneNumber", params, new MethodChannel.Result() {
|
||||||
|
@Override
|
||||||
|
public void success(Object result) {
|
||||||
|
FinAppTrace.d(TAG, "onCustomMenuClick success");
|
||||||
|
// callback.onSuccess(null);
|
||||||
|
phoneNumberCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||||
|
FinAppTrace.e(TAG, "onCustomMenuClick errorCode : " + errorCode + " errorMessage : " + errorMessage);
|
||||||
|
callback.onFailure();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notImplemented() {
|
||||||
|
FinAppTrace.d(TAG, "onCustomMenuClick notImplemented");
|
||||||
|
callback.onFailure();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -268,5 +301,40 @@ public class AppletHandlerModule extends BaseApi {
|
||||||
|
|
||||||
});
|
});
|
||||||
callback.onSuccess(null);
|
callback.onSuccess(null);
|
||||||
|
handler.postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mIAppletHandler.getPhoneNumber(new IAppletHandler.IAppletCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(@androidx.annotation.Nullable JSONObject jsonObject) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 20000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getPhoneNumberResult(String event, Map param, ICallback callback) {
|
||||||
|
FinAppTrace.d("AppletHandlerModule", "getPhoneNumberResult,param:" + param.toString());
|
||||||
|
callback.onSuccess(null);
|
||||||
|
if (phoneNumberCallback != null) {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
try {
|
||||||
|
jsonObject.put("phone", param.get("phone"));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
phoneNumberCallback.onSuccess(jsonObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "2.35.11"
|
version: "2.36.5"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -34,6 +34,9 @@ abstract class AppletHandler {
|
||||||
Future<void> onCustomMenuClick(
|
Future<void> onCustomMenuClick(
|
||||||
String appId, String path, String menuId, String appInfo);
|
String appId, String path, String menuId, String appInfo);
|
||||||
|
|
||||||
//打开小程序
|
///打开小程序
|
||||||
Future<void> appletDidOpen(String appId);
|
Future<void> appletDidOpen(String appId);
|
||||||
|
|
||||||
|
///getMobileNumber
|
||||||
|
Future<void> getMobileNumber(Function(dynamic params) param0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,6 +272,7 @@ class Mop {
|
||||||
if (call.method.startsWith("extensionApi:")) {
|
if (call.method.startsWith("extensionApi:")) {
|
||||||
final name = call.method.substring("extensionApi:".length);
|
final name = call.method.substring("extensionApi:".length);
|
||||||
final handler = _extensionApis[name];
|
final handler = _extensionApis[name];
|
||||||
|
debugPrint("name:$name,handler:$handler");
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
return await handler(call.arguments);
|
return await handler(call.arguments);
|
||||||
}
|
}
|
||||||
|
@ -474,6 +475,10 @@ class Mop {
|
||||||
_extensionApis["appletDidOpen"] = (params) async {
|
_extensionApis["appletDidOpen"] = (params) async {
|
||||||
return handler.appletDidOpen(params["appId"]);
|
return handler.appletDidOpen(params["appId"]);
|
||||||
};
|
};
|
||||||
|
_extensionApis["getPhoneNumber"] = (params) async {
|
||||||
|
return handler.getMobileNumber((params0) =>
|
||||||
|
{_channel.invokeMethod("getPhoneNumberResult", params0)});
|
||||||
|
};
|
||||||
_channel.invokeMethod("registerAppletHandler");
|
_channel.invokeMethod("registerAppletHandler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +532,7 @@ class Mop {
|
||||||
.invokeMethod("setActivityTransitionAnim", {"anim": anim.name});
|
.invokeMethod("setActivityTransitionAnim", {"anim": anim.name});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// 原生发送事件给小程序
|
/// 原生发送事件给小程序
|
||||||
/// [appId] 小程序id
|
/// [appId] 小程序id
|
||||||
|
|
Loading…
Reference in New Issue