How can I open PDF file from remote URL

Put your problem here if it does not fit any of the other categories.

How can I open PDF file from remote URL

Postby laxy » Thu Feb 09, 2012 8:09 pm

I want to open an Remote PDF file.

I try this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         String file = "http://192.168.1.101/a.pdf"; //Remote - don't work
  2.         //String file = "file:///sdcard/a.pdf"; //Local - work fine
  3.  
  4.  
  5.             Intent intent = new Intent();
  6.             intent.setAction(Intent.ACTION_VIEW);
  7.             intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  8.             Uri uri = Uri.parse(file);
  9.             intent.setDataAndType(uri, "application/pdf");
  10.  
  11.             try {
  12.                 startActivity(intent);
  13.             }
  14.             catch (ActivityNotFoundException e) {
  15.                 Log.w("Debug",e);
  16.                 Toast.makeText(MainActivity.this,
  17.                     "No Application Available to View PDF",
  18.                     Toast.LENGTH_SHORT).show();
  19.             }
  20.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


It's worsk only with local files.

Thanks!
laxy
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Oct 21, 2010 7:36 am

Top

Re: How can I open PDF file from remote URL

Postby Phyll » Fri Feb 10, 2012 7:26 am

Hi laxy,

It looks to me like you would have to be connected on the wifi to a server at this ip 192.168.1.101 for this to work. Is that how you are set up? Wifi on, connected and an http server to serve that file out?

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: How can I open PDF file from remote URL

Postby nisha.113a5 » Fri Feb 10, 2012 8:43 am

hi laxy,

Below code may be useful to you. For this you can open your pdf file in google doc.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                        
  2.                     String url = "url for opening the pdf";
  3.                     final String googleDocsUrl = "http://docs.google.com/viewer?url=";
  4.                     Intent intent = new Intent(Intent.ACTION_VIEW);
  5.                     intent.setDataAndType(Uri.parse(googleDocsUrl + url),"text/html");
  6.                     startActivity(intent);
  7.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Nisha
nisha.113a5
Junior Developer
Junior Developer
 
Posts: 14
Joined: Sat Sep 19, 2009 12:35 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests