Showing remote PDF via Intent with Basic Auth

2019-09-13 16:28发布

问题:

I'm trying to show a PDF located in http://myserver.com/my_file.pdf. There is a basic auth for that endpoint. I'm doing this:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://myserver.com/my_file.pdf"));
Bundle bundle = new Bundle();
bundle.putString("Authorization", "Basic xxxxxxxxxxxxxxxxxxxx");
intent.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(intent);

But when I debug the server side, there is no header Authorization in the request so I get 401 Unauthorized.

What am I doing wrong?

回答1:

As you cannot share exact url, I would suggest you to open this inside a webview in your app.

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