2012-03-29 4 views
1

私のアプリはSDカードに保存するリンクからpdlファイルをダウンロードしていますが、うまくいきます。しかし、私は苦労しています。 ...(私はエミュレータ上のPDFビューアをインストールしたが)何もファイルをダウンロードした後に起こりません... ここに私のコードだPDFファイルをopenningため私のアプリが開こうとしている

        InputStream input = new BufferedInputStream(url.openStream()); 
      File sdCard = Environment.getExternalStorageDirectory(); 
      File dir = new File(sdCard.getAbsolutePath() 
        + "/myapp/download"); 
      dir.mkdirs(); 
      File file = new File(dir, "application/pdf"); 
      FileOutputStream output = new FileOutputStream(file); 
+1

投稿する前に検索してください。 [これを読む](http://stackoverflow.com/questions/2456344/display-pdf-within-app-on-android)と[This](http://stackoverflow.com/questions/1697726/how-to- open-pdf-and-read-it) – Calvin

答えて

2

PDFファイルを開くためのコードの下に使用します。

File pdfFile = new File("/mnt/sdcard/path_to_file/yourpdf.pdf"); 
    if(pdfFile.exists()) { 
     Uri path = Uri.fromFile(pdfFile); 
     Intent pdfIntent = new Intent(Intent.ACTION_VIEW); 
     pdfIntent.setDataAndType(path, "application/pdf"); 
     pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     try { 
      startActivity(pdfIntent); 
     } catch(ActivityNotFoundException e) { 
      Toast.makeText(yourActivityClass.this, "No Application available to view pdf", Toast.LENGTH_LONG).show(); 
     } 
    } else { 
     Toast.makeText(yourActivityClass.this, "File not found", Toast.LENGTH_LONG).show(); 
    } 

yourActivityClass.thisは、コードの上にテスト中にそれが正しいするアプリケーション・コンテキストです。

+0

ありがとうございました – AliDeV

関連する問題