uni-app在写原生插件的时候,如何在原生端使用onActivityResult(int requestCode, int resultCode, Intent data),使用JSCallback获取上一个activity的返回值信息。
y***@163.com
- 发布:2020-01-11 09:46
- 更新:2020-01-11 12:30
- 阅读:1356
y***@163.com (作者)
实现如下图,希望帮到人,我试了两三天才知道该怎么弄。
private static final int REQUEST_CODE = 100;
private JSCallback jsCallback;
@JSMethod(uiThread = true)
public void scanFace(JSONObject options,JSCallback _jsCallback) {
if (mWXSDKInstance.getContext() instanceof Activity) {
Intent intent = new Intent(mWXSDKInstance.getContext(), DetectLoginActivity.class);
this.jsCallback=_jsCallback;
((Activity) mWXSDKInstance.getContext()).startActivityForResult(intent, REQUEST_CODE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==REQUEST_CODE && resultCode==Activity.RESULT_OK)
{
boolean login_success = data.getExtras().getBoolean("login_success");
String user_info = data.getExtras().getString("user_info");
String uid = data.getExtras().getString("uid");
double score = data.getExtras().getDouble("score");
JSONObject result = new JSONObject();
result.put("login_success",login_success);
result.put("user_info",user_info);
result.put("uid",uid);
result.put("score",score);
jsCallback.invoke(result);
}
}
6***@qq.com
很有用 感谢
2020-05-14 15:22