gpt4 book ai didi

android - react-native-share 在 android 版本 7 及更高版本中无法正常工作?

转载 作者:搜寻专家 更新时间:2023-11-01 09:27:03 26 4
gpt4 key购买 nike

我正在我的应用程序中使用 react-native-share。共享选项在 android 版本 5 之前工作正常。我不确定它在版本 6 中是否工作正常。

但我确信 share 在版本 7 及更高版本中不起作用。会是什么问题。我吃了一整天。我尝试更改版本

我的分享码是

_downloadImageAndShare(url ,title, message) {
this.setState({loading: true})
RNFetchBlob.config({ fileCache: true })
.fetch('GET', url)
.then(resp => resp.readFile('base64')
.then(base64 => ({ resp, base64 })))
.then(obj => {
const headers = obj.resp.respInfo.headers;
const type = headers['Content-Type'];
const dataUrl = 'data:' + type + ';base64,' + obj.base64;
return { url: dataUrl, title, message };
})
.then(options => {
Share.open(options)
this.setState({loading: false})
});
}

还有

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="26" />



android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
applicationId "com.uplode"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}

但它没有得到工作。确切的问题是(在 android 7 版本中):**

1. whatsapp not even opening while trigger share button.
2. Hangouts only allows to share the url and message, not allowing to share image.
3. E-mail also the same scenario of hangouts

** 我现在该怎么办?提前致谢

最佳答案

这似乎是 API 23 及更高版本的权限问题。尝试下面的快速修复。

import { PermissionsAndroid } from 'react-native';

...

async _downloadImageAndShare(url ,title, message) {
this.setState({loading: true})

const granted = await PermissionsAndroid.check(
'android.permission.WRITE_EXTERNAL_STORAGE'
);
if (!granted) {
const response = await PermissionsAndroid.request(
'android.permission.WRITE_EXTERNAL_STORAGE'
);
if (!response) {
return;
}
}

RNFetchBlob.config({ fileCache: true })
.fetch('GET', url)
.then(resp => resp.readFile('base64')
.then(base64 => ({ resp, base64 })))
.then(obj => {
const headers = obj.resp.respInfo.headers;
const type = headers['Content-Type'];
const dataUrl = 'data:' + type + ';base64,' + obj.base64;
return { url: dataUrl, title, message };
})
.then(options => {
Share.open(options)
this.setState({loading: false})
});

}

此修复将在尝试将 base64 图像共享到 WhatsApp 之前检查所需权限是否处于 Activity 状态。你可以read more on the issue here

关于android - react-native-share 在 android 版本 7 及更高版本中无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49794979/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com