Mad*_*lan 5 android react-native expo
我已经保存了我想使用本地共享的文件 FileSystem.downloadAsync
Share.share 适用于 iOS。如何共享我在 Android 上本地保存的图像?
我试过了
这两种解决方案都不能似乎与世博会的工作。
我正在使用 react-native 版本:https : //github.com/expo/react-native/archive/sdk-31.0.0.tar.gz
FileSystem.downloadAsync(url, FileSystem.documentDirectory+filename).then(({uri})=>{
if(Platform.OS == "android"){
// ???
}
else{
Share.share({url:uri});
}
})
Run Code Online (Sandbox Code Playgroud)
有什么我想念的吗?
小智 7
从 SDK33 开始,即使您使用的是 Android,您也可以使用 Exposharing 将任何类型的文件共享给其他可以处理其文件类型的应用程序。
看 : https: //docs.expo.io/versions/latest/sdk/sharing/
用法非常简单:
import * as Sharing from 'expo-sharing'; // Import the library
Sharing.shareAsync(url) // And share your file !
Run Code Online (Sandbox Code Playgroud)
为了让用户共享我们(Expo)应用程序中保存的内容,我们将其结构如下。(这适用于 iOS 和 Android)。
import * as FileSystem from 'expo-file-system';
import * as Sharing from 'expo-sharing';
Run Code Online (Sandbox Code Playgroud)
<Button
name="share"
onPress={() =>
openShareDialogAsync(media, {
video: media.meta.fileType === 'video',
})
}
/>
Run Code Online (Sandbox Code Playgroud)
const openShareDialogAsync = async (mediaProp, options) => {
const fileDetails = {
extension: options.video ? '.mp4' : '.jpg',
shareOptions: {
mimeType: options.video ? 'video/mp4' : 'image/jpeg',
dialosTitle: options.video
? 'Check out this video!'
: 'Check out this image!',
UTI: options.video ? 'video/mp4' : 'image/jpeg',
},
};
const downloadPath = `${FileSystem.cacheDirectory}${mediaProp.media_id}${fileDetails.extension}`;
const { uri: localUrl } = await FileSystem.downloadAsync(
mediaProp.url,
downloadPath
);
if (!(await Sharing.isAvailableAsync())) {
showMessage({
message: 'Sharing is not available',
description: 'Your device does not allow sharing',
type: 'danger',
});
return;
}
await Sharing.shareAsync(localUrl, fileDetails.shareOptions);
};
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助 :]
| 归档时间: |
|
| 查看次数: |
4184 次 |
| 最近记录: |