android - Downlad PDF from URL -
i have written code download files url. downloaded doc , jpg files. pdf files not downloaded , shows com.android.volley.clienterror. url contains "શુભમ08_23_2016_06_05_33.pdf". problem because of gujrati characters in url?
this code:
inputstreamvolleyrequest request = new inputstreamvolleyrequest(request.method.get, murl, new response.listener<byte[]>() { @override public void onresponse(byte[] response) { // todo handle response try { if (response!=null) { pd.dismiss(); fileoutputstream outputstream; features features=new features(context); string name=features.findname(murl);;//<file_name_with_extension e.g reference.txt> file sdcard = environment.getexternalstoragedirectory(); file dir = new file (sdcard.getabsolutepath() + "/aio"); if (!dir.isdirectory()) { dir.mkdirs(); } file file = new file(dir, name); fileoutputstream f = new fileoutputstream(file); //f=context.openfileoutput(name, context.mode_private); f.write(response); f.close(); features.toastcenter("file downloaded in aio folder",true); intent intent = new intent(intent.action_view); string extension=features.findextension(murl); intent.setdataandtype(uri.fromfile(file),"application/"+extension); intent.setflags(intent.flag_activity_clear_top); intent.setflags(intent.flag_activity_new_task); try { boolean isfileopened=false; try { context.startactivity(intent); isfileopened=true; } catch (exception e) { //don't show message here } if (!isfileopened) { try { intent.setdataandtype(uri.fromfile(file),"application/msword"); intent.setflags(intent.flag_activity_clear_top); intent.setflags(intent.flag_activity_new_task); context.startactivity(intent); } catch (exception e) { features.toastcenter("can not view file",true); } } } catch (activitynotfoundexception e) { } } } catch (exception e) { // todo auto-generated catch block log.d("key_error", "unable download file"); e.printstacktrace(); } } } ,new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { features features=new features(context); features.toastcenter("failed download file",true); // todo handle error error.printstacktrace(); pd.dismiss(); } }, null); requestqueue mrequestqueue = volley.newrequestqueue(context, new hurlstack()); mrequestqueue.add(request);
Comments
Post a Comment