java - PDF file path is incorrect -


this question has answer here:

i want open pdf file in application goes wrong everytime. yeah , watched many topics it, none of them helped me.

here photos of error:

http://i.stack.imgur.com/tzpo2.jpg

http://i.stack.imgur.com/cuoem.jpg

 btn3.setonclicklistener(new view.onclicklistener() {                                 @override                                 public void onclick(view v) {                                     //startactivity(new intent(mainactivity.this, activity2.class));                                     file file = null;                                     file = new file(environment.getexternalstoragedirectory() + "/raw/" + "tirepressuremonitoringsystem3.pdf");                                     toast.maketext(getapplicationcontext(), file.tostring() , toast.length_long).show();                                     if(file.exists()) {                                         intent target = new intent(intent.action_view);                                         target.setdataandtype(uri.fromfile(file), "application/pdf");                                         target.setflags(intent.flag_activity_no_history);                                          intent intent = intent.createchooser(target, "open file");                                         try {                                             startactivity(intent);                                         } catch (activitynotfoundexception e) {                                             // instruct user install pdf reader here, or                                         }                                     }                                     else                                         toast.maketext(getapplicationcontext(), "file path incorrect." , toast.length_long).show();                                 }                             }     ); 

maybe error put these files in /raw ? should store them in assest folder instead?

replace line

 file = new file(environment.getexternalstoragedirectory() + "/raw/" + "tirepressuremonitoringsystem3.pdf"); 

with line

 file = new file("android.resource://com.cpt.sample/raw/tirepressuremonitoringsystem3.pdf"); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -