Android : Show a pdf in android Webview with authendication

on Tuesday, August 5, 2014


I am working in an android application an I want to open a pdf from a link in an android webview. But the link has implemented authendication. I am not able to open that link with pdf.But if I place a link without the pdf, I am able to see the web page in the android webview.So the authendication works fine. The problem is when I append "https://docs.google.com/gview?embedded=true&url=" to the url to open the pdf.


Please look into my code.



public class MainActivity extends Activity {

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

WebView webview = new WebView(MainActivity.this);
webview.getSettings().setJavaScriptEnabled(true);
String url=
"https://docs.google.com/gview?embedded=true&url=" +"http://spahousingli.evero.com/SPADocuments/Forms/Clients/Admissions/ADM000000011.pdf";


webview.loadUrl(url);
webview.setWebViewClient(new WebViewClient() {
public void onReceivedHttpAuthRequest(WebView view,
android.webkit.HttpAuthHandler handler, String host,
String realm) {

handler.proceed("username", "password");
};
});
setContentView(webview);

}
}

0 comments:

Post a Comment