gpt4 book ai didi

javascript - Android原生分享菜单: Detect supporting browsers

转载 作者:行者123 更新时间:2023-11-28 02:24:21 24 4
gpt4 key购买 nike

我正在开发一个使用 webview 的 Android 应用程序,其中包含如下所示的代码。

函数 shareArticle() 旨在根据对 navigator.share(Google 调用 native 共享菜单的 API)的支持来过滤浏览器并相应地执行操作。然而,当点击调用该函数的按钮时没有任何反应,至少一个警报提示会很方便。

知道如何使用 native Android 共享屏幕共享内容吗?

export const shareArticle = () => {
return AndroidNativeShare("Title", "www.google.com", 'description');
};

async function AndroidNativeShare(Title, URL, Description) {
if (typeof navigator.share === 'undefined' || !navigator.share) {
alert('Your browser does not support Android Native Share, it\'s tested on chrome 63+');
} else if (window.location.protocol != 'https:') {
alert('Android Native Share support only on Https:// protocol');
} else {
if (typeof URL === 'undefined') {
URL = window.location.href;
}
if (typeof Title === 'undefined') {
Title = document.title;
}
if (typeof Description === 'undefined') {
Description = 'Share your thoughts about ' + Title;
}
const TitleConst = Title;
const URLConst = URL;
const DescriptionConst = Description;

try {
await navigator.share({title: TitleConst, text: DescriptionConst, url: URLConst});
} catch (error) {
console.log('Error sharing: ' + error);
return;
}
}
}

最佳答案

检查是否存在 navigator.share 是推荐的合乎逻辑的解决方案。不幸的是,这在 WebView 中似乎不起作用。请在此处查看提交的错误:https://bugs.chromium.org/p/chromium/issues/detail?id=765923

关于javascript - Android原生分享菜单: Detect supporting browsers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55380807/

24 4 0