开发者

How to store pdf file from asset folder to memory card in android

开发者 https://www.devze.com 2023-02-28 03:44 出处:网络
Hi friends I have pdf file in asset folder now i want to store that pdf file to sdcard .and I want to display pdf in webview can anyb开发者_开发问答ody tell how to do?

Hi friends I have pdf file in asset folder now i want to store that pdf file to sdcard .and I want to display pdf in webview can anyb开发者_开发问答ody tell how to do?

Thanks


Use AssetManager to get the pdf:

AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("your_pdf.pdf");

and then you can write that to the card:

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);

and display it

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消