I try to open pdf, but when I press the button, nothing happens. Where is my mistake?
OnClickListener oclBt2 = new OnClickListener(){
public void onClick(View v) {
File file = new File("http://testserv1.p.ht/1/ksu016.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
}
};
I corrected my code, but it doesn't work again :( when I press the button, appears the window(Sorry, but my reputation doesn't allow to post images)
OnClickListener oclBt2 = new OnClickListener(){
public void onClick(View v) {
Uri path = Uri.parse("http://testserv1.p.ht/1/ksu016.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url=http://hostforandroid.elitno.net/pdf-test.pdf" );
setContentView(mWebView);
}
}
};