In Android Studio Pdf/.doc file is corrupted after downloading it from Download Manager -
1) after downloading .docx/pdf file in android studio through download manager shows me message "unreadable content in file. want recover it?"
2) when download jpg or mp3, works fine.
my code:
private long downloaddata (uri uri, view v) { long downloadreference; downloadmanager = (downloadmanager)getsystemservice(download_service); downloadmanager.request request = new downloadmanager.request(uri); //setting title of request request.settitle("zoraizcv"); request.setallowednetworktypes(downloadmanager.request.network_wifi | downloadmanager.request.network_mobile); request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); //setting description of request request.setdescription("android data download using downloadmanager."); //set local destination downloaded file path within application's external files directory if(v.getid() == r.id.downloadmusic) request.setdestinationinexternalfilesdir(mainactivity.this, environment.directory_downloads,"zoraizcv.docx"); request.allowscanningbymediascanner(); //enqueue download , save referenceid downloadreference = downloadmanager.enqueue(request); button downloadstatus = (button) findviewbyid(r.id.downloadstatus); downloadstatus.setenabled(true); button canceldownload = (button) findviewbyid(r.id.canceldownload); canceldownload.setenabled(true); return downloadreference; }
public class puneuniversity_mechanical_engineering_se extends appcompatactivity { // remove below line after defining own ad unit id. private static button btn_download; downloadmanager downloadmanager;
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_puneuniversity_mechanical__engineering__se); // load ad admob banner view. adview adview = (adview) findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder() .setrequestagent("android_studio:ad_template").build(); adview.loadad(adrequest); btn_download=(button)findviewbyid(r.id.download); btn_download.setonclicklistener( new view.onclicklistener() { @override public void onclick(view view) { downloadmanager= (downloadmanager) getsystemservice(context.download_service); uri uri= uri.parse("https://drive.google.com/uc?export=download&id=0b6c5vnwhm0scsvlxz3ljtna3tjg"); downloadmanager.request request=new downloadmanager.request(uri); request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); long reference=downloadmanager.enqueue(request); } } ); }
Comments
Post a Comment