android - How can i open pdf from sdcard i can from asset folder -
i using pdf viewer library , able show pdf asset folder while trying sdcard showing progrss bar long time.
i using below code showing asset
assetmanager assetmanager = getassets(); inputstream in = null; outputstream out = null; file file = new file(getfilesdir(), "sample.pdf"); try { in = assetmanager.open("sample.pdf"); out = openfileoutput(file.getname(), context.mode_world_readable); copyfile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (exception e) { log.e("tag", e.getmessage()); } intent intent = new intent(this, mypdfvieweractivity.class); intent.putextra(pdfvieweractivity.extra_pdffilename, getfilesdir() + "/sample.pdf"); startactivity(intent); } private void copyfile(inputstream in, outputstream out) throws ioexception { byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }}
and using below code showing sdcard
intent intent = new intent(this, mypdfvieweractivity.class); intent.putextra(pdfvieweractivity.extra_pdffilename, "mnt/sdcard/sample.pdf"); /* intent.putextra(pdfvieweractivity.extra_pdffilename, "assets/sample.pdf");*/ startactivity(intent); }
you can try access pdf file sdcard this:
file mypdffile = new file(environment.getexternalstoragedirectory(),"sample.pdf"); string path = mypdffile.getabsolutepath(); //open pdf method openpdffilewithfilepath(path); protected void openpdffilewithfilepath(string path) { // todo auto-generated method stub try { final intent intent = new intent(this, mypdfvieweractivity.class); intent.putextra(pdfvieweractivity.extra_pdffilename,path); startactivity(intent); } catch (exception e) { e.printstacktrace(); } }
i hope helps.
Comments
Post a Comment