React Native Share file or link

送分小仙女□ 提交于 2021-01-02 06:59:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!