javascript - Android原生分享菜单:检测支持的浏览器
问题描述
我正在开发一个使用 webview 的 Android 应用程序,其中包含如下发布的代码。
函数 shareArticle() 旨在根据对 navigator.share(Google 的 API 调用本机共享菜单)的支持过滤浏览器并相应地执行操作。但是,单击调用该函数的按钮时没有任何反应,至少警报提示会很方便。
知道如何制作,以便可以使用原生 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
是推荐和合乎逻辑的解决方案。不幸的是,这似乎在 webviews 中不起作用。请参阅此处提交的错误:https ://bugs.chromium.org/p/chromium/issues/detail?id=765923
推荐阅读
- gradle - Gradle 从键盘输入密码:System.console() return null
- javascript - 如何在 Vue 2 渲染功能中使用插槽?
- c++ - C++/CLI 项目,C++ 共享库的包装器,出现错误
- android - 如何在 Android 上监听 LLMNR 数据包?
- typescript - 使用 javascript 在 BaseClientSideWebPart 的渲染函数中添加代码
- javascript - ngmodel 中的最小值和最大值验证
- php - wp_list_table 中的批量操作
- javascript - JS Jquery 如何选择鼠标点击 Target > parent > .Class
- oracle - Oracle Apex 19.1 中的上传向导限制
- php - PHP cURL 发布数据未发送到目标 url