【问题标题】:Load PDF from URL with Authentication通过身份验证从 URL 加载 PDF
【发布时间】:2019-10-30 20:45:30
【问题描述】:

我想在WebView 中显示一个.pdf 文件,该文件正在进行身份验证。该应用已被 Google 拒绝,因为我正在使用意图加载 WebView

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://UserName:password@myUrl", "text/html");mContext.startActivity(intent);

【问题讨论】:

    标签: android android-intent android-webview basic-authentication pdfview


    【解决方案1】:

    很遗憾,您不能在 android 中使用 https://username:password@url

    您必须在捆绑的请求属性中添加基本授权

    Bundle bundle = new Bundle();
    String basicAuth = USERNAME + ":" + PASSWORD
    basicAuth = "Basic " + new String(Base64.encode(basicAuth.getBytes(),Base64.NO_WRAP));
    bundle.putString("Authorization", basicAuth);
    intent.putExtra(Browser.EXTRA_HEADERS, bundle);
    

    您可能还需要:

    webView.setJavaScriptEnabled(true);
    webview.loadUrl(<URL>);
    

    【讨论】:

    • 我已经尝试使用上面的代码。现在浏览器显示输入用户名和密码的字段。
    猜你喜欢
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多