public void dataToJS(Callback successBack, Callback errorBack){
try{
Activity currentActivity = getCurrentActivity();
String result = currentActivity.getIntent().getStringExtra(“data”);
if (TextUtils.isEmpty(result)){
result = “没有数据”;
}
successBack.invoke(result);
}catch (Exception e){
errorBack.invoke(e.getMessage());
}
}
//注意:startActivityFromJS、dataToJS方法添加RN注解(@ReactMethod),否则该方法将不被添加到RN中
}
第三步,创建MyReactPackage类
实现ReactPackage接口暴露给RN调用,在createNativeModules里注册上一步添加的模块:
/**
- 注册模块
*/
public class MyReactPackage implements ReactPackage {
@Override
public List createNativeModules(ReactApplicationContext reactContext) {
return Arrays.asList(new MyIntentModule(reactConte