如何在 webview 中打开 android 默认共享对话框

how to open android default share dialog in webview

我已经使用 webview 创建了一个应用程序,现在我想创建一个共享按钮(在 web 和 js 中)以打开 android 用户的默认共享对话框。

但是这个方法行不通:

const sharePromise = navigator.share(data);

因为 Android Web 视图不支持此功能。 我能做什么?

可以调用自定义JS桥接函数打开分享。喜欢下面

@JavascriptInterface
fun share(pMessage: String) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_TEXT, pMessage);
sharingIntent.setType("text/plain");
startActivity(Intent.createChooser(sharingIntent, “ChooserTitle"));  
}