In my Android app, I have various URLs that I access from a database and then open a WebView to display that URL. Typically the url looks something like this:
You can find out what mime type of content in such way:
webView.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
//here you getting the String mimetype
//and you can do with it whatever you want
}
});
In this method you can check if mimetype is pdf and show it through Google Docs in WebView using modified url like this:
String pdfPrefixUrl = "https://docs.google.com/gview?embedded=true&url="
if ("application/pdf".equals(mimetype)) {
String newUrl = pdfPrefixUrl + url;
webView.loadUrl(newUrl);
}
Hope it will help!