Loading and Viewing a local (in bundle) pdf within Android App -
i have reviewed , tried numerous versions of issue no avail. have seen answers far 2011 , recent mid-year 2014. unfortunately, many partial answers , poorly explained suggestions have created more questions answers. have apple app available in itunes app store performs trying android app. in apple app world viewing pdf file relatively easy perform having difficult time accomplishing in android. admit limited in experience @ creating android apps.
the problem have android app main activity has listview lists titles 35 diagrams in pdf format. each of these clickable viewing in full screen activity (view). each pdf half page width , anywhere 1/2 page 2 pages in length. new activity (pdf view) need scrollable. since app phones or pads new activity (pdf view) needs zoomable. after user completes view of pdf need option return main activity. user can select diagram viewing.
the things have accomplished are: - listview of diagram titles on main activity - listener enabled each entry in listview - new activity (pdf view) accessed - using putextras - getextras variable passing, working
some code (from main activity.java):
@override public void onclick(view v) { string scroll_page = new string("commonvehiclecodeviolations.pdf"); intent intent = new intent(this, scroll_view.class); intent.putextra("extra_scroll_page", scroll_page); startactivity(intent); }
the diagram title hard coded testing purposes. now, code new activity (pdf view) 'scroll_view.java':
public class scroll_view extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_scroll_view); bundle extras = getintent().getextras(); string scroll_page = null; if (extras != null) { scroll_page = extras.getstring("extra_scroll_page"); } int currentpage = 1; imageview imageview = (imageview) findviewbyid(r.id.imageview); bitmap bitmap = bitmap.createbitmap(500,500, bitmap.config.argb_4444); try { file file = new file(getfilesdir(), scroll_page); pdfrenderer renderer = new pdfrenderer(parcelfiledescriptor.open(file,parcelfiledescriptor.mode_read_only)); if(currentpage < 0) { currentpage = 0; } else if (currentpage > renderer.getpagecount()) { currentpage = renderer.getpagecount() - 1; } renderer.openpage(currentpage).render(bitmap, new rect(0, 0, 500, 500), new matrix(),pdfrenderer.page.render_mode_for_display); imageview.setimagebitmap(bitmap); imageview.invalidate(); } catch (ioexception e) { e.printstacktrace(); }
this attempt use 1 of many posted answers suggested using pdfrenderer. example new activity (pdf view) blank screen. hoping 2015 bring new answers. please help.
why not try using intent , let system show list of compatible apps:
file file = new file(getfilesdir(), scroll_page); intent intent = new intent(intent.action_view); intent.setdataandtype(uri.fromfile(file), "application/pdf"); intent.setflags(intent.flag_activity_no_history); startactivity(intent);
Comments
Post a Comment