【问题标题】:how to open android default share dialog in webview如何在 webview 中打开 android 默认共享对话框
【发布时间】:2021-01-09 13:55:52
【问题描述】:

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

但是这种方法行不通:

const sharePromise = navigator.share(data);

因为这在 Android Web View 中不受支持。 我该怎么办?

【问题讨论】:

    标签: javascript java android android-studio webview


    【解决方案1】:

    您可以通过调用自定义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"));  
    }
    

    【讨论】:

    • 谢谢。以及如何从网络调用此函数??
    • 我做到了。它在 android 8 中工作,但在 android 10 中不工作
    • 奇怪..它应该在android 10上工作。请分享您的webview设置和JSInterface代码..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-26
    • 2019-06-25
    • 1970-01-01
    • 2015-06-01
    • 2011-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多