Cannot open a file that was created in the temporary folder of an Android app - file does not exist or cannot be read -


when run code below prompt open file appropriate reader file not displayed.

i new android app development , appreciated.

url url = new url(dwnload_file_path); httpurlconnection urlconnection = (httpurlconnection) url.openconnection();  urlconnection.setrequestmethod("get"); urlconnection.setdooutput(true);  //connect urlconnection.connect();  file = file.createtempfile("christo", ".pdf"); fileoutput = new fileoutputstream(file);  //stream used reading data internet inputstream inputstream = urlconnection.getinputstream();  //this total size of file downloading totalsize = urlconnection.getcontentlength();  runonuithread(new runnable() {     public void run() {         pb.setmax(totalsize);     } });  //create buffer... byte[] buffer = new byte[1024]; int bufferlength;  while ((bufferlength = inputstream.read(buffer)) > 0) {     fileoutput.write(buffer, 0, bufferlength);     downloadedsize += bufferlength;     // update progressbar //     runonuithread(new runnable() {         public void run() {             pb.setprogress(downloadedsize);             float per = ((float) downloadedsize / totalsize) * 100;             cur_val.settext("downloaded " + downloadedsize + "kb / " + totalsize + "kb (" + (int) per + "%)");         }     }); } //close output stream when complete // fileoutput.close(); runonuithread(new runnable() {     public void run() {         // not close progressbar     } });  } catch (final malformedurlexception e) {     showerror("error : malformedurlexception " + e);     e.printstacktrace(); } catch (final ioexception e) {     showerror("error : ioexception " + e);     e.printstacktrace(); } catch (final exception e) {     showerror("error : please check internet connection " + e); }  uri uri = uri.fromfile(file); intent intent = new intent(); intent.setaction(intent.action_view); intent.setflags(intent.flag_grant_read_uri_permission); intent.setdataandtype(uri, "application/pdf"); startactivity(intent); 

i think while creating file should be

file = file.createtempfile("christo", "pdf"); 

the . [dot] not required


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -