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

Javascript 如何在webview中打开android默认共享对话框,javascript,java,android,android-studio,webview,Javascript,Java,Android,Android Studio,Webview,我已经使用webview创建了一个应用程序,现在我想创建一个共享按钮(在web和js中)来为用户打开android默认共享对话框 但这种方法不起作用: const sharePromise = navigator.share(data); 因为这在Android Web视图中不受支持。 我能做什么?您可以通过调用自定义JS桥函数打开共享。如下 @JavascriptInterface fun share(pMessage: String) { Intent sharingIntent = ne

我已经使用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"));  
}

谢谢我怎样才能从网络上调用这个函数呢?我做到了。它可以在安卓8上工作,但不能在安卓10上工作。奇怪的是,它应该可以在安卓10上工作。请分享您的webview设置和JSInterface的代码。。