試試這個以獲取意圖參數在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。 –