试试这个以获取意图参数在react-native应用程序。
在我的本机应用程序,我用这个代码:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.my.react.app.package");
launchIntent.putExtra("test", "12331");
startActivity(launchIntent);
在反应本地的项目,我MainActivity.java
public class MainActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "FV";
}
public static class TestActivityDelegate extends ReactActivityDelegate {
private static final String TEST = "test";
private Bundle mInitialProps = null;
private final
@Nullable
Activity mActivity;
public TestActivityDelegate(Activity activity, String mainComponentName) {
super(activity, mainComponentName);
this.mActivity = activity;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
Bundle bundle = mActivity.getIntent().getExtras();
if (bundle != null && bundle.containsKey(TEST)) {
mInitialProps = new Bundle();
mInitialProps.putString(TEST, bundle.getString(TEST));
}
super.onCreate(savedInstanceState);
}
@Override
protected Bundle getLaunchOptions() {
return mInitialProps;
}
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new TestActivityDelegate(this, getMainComponentName());
}
}
在我的第一个集装箱我得到this.props帕拉姆
export default class App extends Component {
render() {
console.log('App props', this.props);
//...
}
}
完整的例子我发现这里: http://cmichel.io/how-to-set-initial-props-in-react-native/
什么是不以'getIntent工作“第二项活动? –
第二项活动是反应原生的。所以我的问题是我如何获得反应原生getIntent。 –