java - Parse the url to other Activity to load PDF from that url -
i have 2 activity's in app. 1 has 3 buttons , other has pdfview github "com.github.barteksc:android-pdf-viewer:2.6.1" trying load pdf url code. works me
public class pdfactivity extends appcompatactivity { pdfview pdfview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_pdf); pdfview = (pdfview) findviewbyid(r.id.pdfview); new retrievepdfstream().execute("my url load pdf example http://sample.com/xyz.pdf"); } class retrievepdfstream extends asynctask<string, void, inputstream> { @override protected inputstream doinbackground(string... strings) { inputstream inputstream = null; try { url url = new url(strings[0]); httpurlconnection urlconnection = (httpurlconnection)url.openconnection(); if(urlconnection.getresponsecode() == 200) { inputstream = new bufferedinputstream(urlconnection.getinputstream()); } } catch (ioexception e) { return null; } return inputstream; } @override protected void onpostexecute(inputstream inputstream) { pdfview.fromstream(inputstream); } } }
this works fine, have load pdf activity 1 other url, change url "new retrievepdfstream" when click button 1 load pdf in activity , button 2 load pdf activity.
any answers highly appreciated!
if understand correctly have 3 buttons , 2 actvities.
in ack1 have 3 buttons , in ack2 have pdf viewer. if click on ack1 button1 want load url1 ack2 , if click on ack1 button2 want load url2 form ack2 , on.... if requirement can use intent extras. form ack1 this:
button1.onclick(new onclicklistener{ publi void onclick(){ intent intent=new intent(this,ack2.class); intent.putextras("url","pdf url1"); }}
for button2 jst change "pdf url1" "pdf url2"
button3 jst change "pdf url1" "pdf url3"
in ack2 this: in oncreate() method:
intent i=this.getintent(); string url=i.getextras("url");
from here url passed in first activity based on button clicked . if user clicked on button 1 "pdf url1", if clciked on button2 "pdf url2".. on...
edit:code reference dont copy &paste it...
Comments
Post a Comment