Open and view pdf in my application

Using this code:

try { URL url = new URL(aurl[0]); URLConnection conexion = url.openConnection(); conexion.connect(); int lenghtOfFile = conexion.getContentLength(); Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile); InputStream input = new BufferedInputStream(url.openStream()); FileOutputStream fos = openFileOutput("try.pdf", Context.MODE_PRIVATE); //PARA DESCARGARLO EN SD// // OutputStream output = new FileOutputStream("/sdcard/prueba.pdf"); byte data[] = new byte[1024]; long total = 0; while ((count = input.read(data)) != -1) { total += count; publishProgress(""+(int)((total*100)/lenghtOfFile)); fos.write(data, 0, count); } fos.flush(); fos.close(); input.close(); } catch (Exception e) {} return null; 

I save an 8 MB PDF in the application. I used several codes to try to open it and look, but I can not find a way.

Any suggestions?

+2
android pdf viewer
Jun 27 2018-12-12T00:
source share
2 answers

See the Response link below to read a pdf file from an SD card using PDFViewer.

Read PDF Files

+2
Jun 27. '12 at 11:22
source share

Hi, please try the code below.

 Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File("mnt/sdcard/try.pdf")), "application/pdf"); try { startActivity(intent); } catch (ActivityNotFoundException e) { // Toast Message } 

Here is the sFile path of the SDcard .

+1
Jun 27 2018-12-12T00:
source share



All Articles