2017-08-11 133 views

回答

0

或許這可以成爲有用的人,所以我張貼我的答案:

private void openPdf(String pdfName){ 
    AssetManager assetManager = getAssets(); 

    InputStream in = null; 
    OutputStream out = null; 
    File file = new File(getFilesDir(), pdfName); 
    try 
    { 
     in = assetManager.open(pdfName); 
     out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); 

     byte[] buffer = new byte[1024]; 
     int read; 
     while ((read = in.read(buffer)) != -1) 
     { 
      out.write(buffer, 0, read); 
     } 
     in.close(); 
     in = null; 
     out.flush(); 
     out.close(); 
     out = null; 
    } catch (Exception e) 
    { 
     Log.e("tag", e.getMessage()); 
    } 

    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(
      Uri.parse("file://" + getFilesDir() + "/"+pdfName), 
      "application/pdf"); 

    startActivity(intent); 
} 

PDF文件是資產的文件夾內的商店

相關問題