简体   繁体   中英

Accessing Bundle from React Native

I need to pass some data (specifically, the contents of a received SMS but I'm not sure how relevant that is) from "Android land" (ie native code) to React Native activity. Now, I believe that in native code, using a bundle is the right option but is there a way to access that data from the ReactActivity?

Intent i = new Intent();
i.setClassName("com.example.domain", "com.example.domain.MainActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("foobar", AnyValue);  
context.startActivity(i);

Can I access foobar from RN code?

You can use https://github.com/CentaurWarchief/react-native-android-sms-listener .

Usage looks like this:

import SmsListener from 'react-native-android-sms-listener'

SmsListener.addListener(message => {
  console.info(message)
})

Or create your own module with method that returns a promise with SMS content. See documentation https://facebook.github.io/react-native/docs/native-modules-android.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM