嗨朋友们 我在资产文件夹中有pdf文件,现在我想将该pdf文件存储到SD卡。我想在webview中显示pdf,有人可以告诉我该怎么做吗?
由于
答案 0 :(得分:-1)
使用AssetManager获取pdf:
AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("your_pdf.pdf");
然后你可以把它写到卡片上:
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdcard.getAbsolutePath() + "/where/you/want/it");
dir.mkdirs();
File file = new File(dir, "your_pdf.pdf");
FileOutputStream f = new FileOutputStream(file);
并显示它
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, "application/pdf");
startActivity(intent);