问题
Not sure what this is called, but on Android an app is able to bring up this window, and if I select, say Gmail, it will automatically create a file attachment in Gmail.
How can I achieve this in React Native with Expo (without detaching)?
回答1:
You are looking for something like react-native-share.
Since you're using Expo, you'll probably want to use Linking (Opening links to other apps) which points you to using react-native-app-link. Or for something more complicated on the Android side, the IntentLauncherAndroid with some custom code could work as well.
Keywords to help you look for more information are sharing, linking, deep linking, and if you know Android development, Intents.
回答2:
Without ejecting the IntentLauncherAndroid is the way to go, since you can emit intents for anything listed at the Android Dev Documentation
For an intend to share a file based on an URI you can do:
IntentLauncherAndroid.startActivityAsync("android.intent.action.SEND", { URI: uri });
This also works to open a file with the default app on a device:
IntentLauncherAndroid.startActivityAsync("android.intent.action.VIEW", { URI: uri });
回答3:
Try these package, it can support all file format
https://www.npmjs.com/package/react-native-file-share-for-android
来源:https://stackoverflow.com/questions/49819168/react-native-share-file-or-link