I'm searching on the web how to open pdf file from server with default pdf viewer on android. What I found is download the file first then start it in intent or load it with google docs. I don't want to do all these. I just want to load it directly from server in default pdf viewer from phone. I've tried opening video url with intent and it worked. But opening pdf url with intent is not working. Below is my code;
private void openFilePDF(){
try{
Toast.makeText(getBaseContext(), "Opening PDF... ", Toast.LENGTH_SHORT).show();
Intent inte = new Intent(Intent.ACTION_VIEW);
inte.setDataAndType(
Uri.parse("http://122.248.233.68/pvfiles/Guide-2.pdf"),
"application/pdf");
startActivity(inte);
}catch(ActivityNotFoundException e){
Log.e("Viewer not installed on your device.", e.getMessage());
}
}
Is there any way that I can load pdf url in intent?
First Create a downloader class
After that create an activity which downloads the PDF file from internet,
Finally at last declare persmissions in
AndroidManifest.xml
You can try this using WebView:
According to me there is no way to directly open your PDF file on device. Because of browser properties of android devices when we try to open PDF file it download to device. There is only Two way to open the PDF file.
You can use PDF application Intent to choose app to open file with.
You can append your server url for file with Google docs url and can open it in browser so ur PDF file will open in browser