2

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 keep in the application a PDF of 8 MB size. I've used several codes to try to open it and view it but can not find the way.

Any suggestions?

overbet13
  • 1,666
  • 1
  • 19
  • 36
jlopez
  • 6,287
  • 2
  • 51
  • 90

2 Answers2

2

Please see below SO Answer's link for read pdf from sdcard using PDFViewer.

Read PDF Files

Community
  • 1
  • 1
Dipak Keshariya
  • 22,009
  • 18
  • 75
  • 127
1

Hi Please try below code.

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 sFile is SDcard Path.

Mehul Mistri
  • 14,954
  • 14
  • 67
  • 94
Nikhil
  • 16,026
  • 20
  • 63
  • 81