2

使用此代码:

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;

我在应用程序中保留了一个 8 MB 大小的 PDF。我已经使用了几个代码来尝试打开它并查看它,但找不到方法。

有什么建议么?

4

2 回答 2

2

请参阅下面的 SO Answer 链接,以使用 PDFViewer 从 sdcard 读取 pdf。

阅读 PDF 文件

于 2012-06-27T11:22:05.377 回答
1

嗨,请尝试下面的代码。

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
}

sFileSDcard 路径

于 2012-06-27T10:49:54.643 回答