Dealing with Download Listener in Android -
hello i'm new android studio , i'm dealing downloadlistener in webview in order download files has been uploaded on web page, can file in pdf format,however tried level best find error couldn't found one.the error lies in moment click on downloadable link on webpage shows error goes that:
02-05 22:47:29.425 3531-3531/myapp.hp.com.abhivyakti e/androidruntime: fatal exception: main process: myapp.hp.com.abhivyakti, pid: 3531 java.lang.securityexception: no permission write /storage/emulated/0/download/download: neither user 10059 nor current process has android.permission.write_external_storage. @ android.os.parcel.readexception(parcel.java:1599) @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:183) @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:135) @ android.content.contentproviderproxy.insert(contentprovidernative.java:476) @ android.content.contentresolver.insert(contentresolver.java:1231) @ android.app.downloadmanager.enqueue(downloadmanager.java:946) @ myapp.hp.com.abhivyakti.notification.notifyfragment$3.ondownloadstart(notifyfragment.java:95) @ com.android.webview.chromium.webviewcontentsclientadapter.ondownloadstart(webviewcontentsclientadapter.java:884) @ com.android.org.chromium.android_webview.awcontentsclientcallbackhelper$myhandler.handlemessage(awcontentsclientcallbackhelper.java:112) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5417) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)
my code activity given below:
public class notifyfragment extends fragment { public notifyfragment() { // required empty public constructor } private webview webview; private progressbar pb; private connectivitymanager cmanager; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment view view = inflater.inflate(r.layout.fragment_notify, container, false); webview = (webview)view.findviewbyid(r.id.notifywebview); pb = (progressbar)view.findviewbyid(r.id.notifyprogressbar); cmanager = (connectivitymanager) getactivity().getsystemservice(getactivity().connectivity_service); networkinfo ninfo = cmanager.getactivenetworkinfo(); if (ninfo == null) { alertdialog.builder builder = new alertdialog.builder(getactivity()); builder.setmessage("no internet connection") .settitle("oops!!") .seticon(r.drawable.caution); builder.setcancelable(false); builder.setpositivebutton("try again", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { webview.loadurl("https://docs.google.com/document/d/12u6jzoy8zb11valb2fwmyrf0hcwdnovckokzggnu1ba/edit?usp=sharing"); } }); alertdialog alert = builder.create(); alert.show(); }else { webview.loadurl("https://docs.google.com/document/d/12u6jzoy8zb11valb2fwmyrf0hcwdnovckokzggnu1ba/edit?usp=sharing"); } //getactivity().getwindow().requestfeature(window.feature_progress); getactivity().getwindow().setfeatureint(window.feature_progress, window.progress_visibility_on); webview.setwebchromeclient(new webchromeclient() { public void onprogresschanged(webview view, int progress) { //make bar disappear after url loaded, , changes string loading... pb.setprogress(progress * 100); //make bar disappear after url loaded // return app name after finish loading if (progress == 100) { pb.setvisibility(view.gone); } else { pb.setvisibility(view.visible); } } }); webview.setwebviewclient(new mywebclient()); webview.getsettings().setjavascriptenabled(true); webview.loadurl("https://docs.google.com/document/d/12u6jzoy8zb11valb2fwmyrf0hcwdnovckokzggnu1ba/edit?usp=sharing"); webview.setdownloadlistener(new downloadlistener() { public void ondownloadstart(string url, string useragent, string contentdisposition, string mimetype, long contentlength) { downloadmanager.request request = new downloadmanager.request( uri.parse(url)); request.allowscanningbymediascanner(); request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); request.setdestinationinexternalpublicdir(environment.directory_downloads, "download"); downloadmanager dm = (downloadmanager) getactivity().getsystemservice(getactivity().download_service); dm.enqueue(request); toast.maketext(getactivity(), "downloading file", toast.length_short).show(); } }); return view; } public class mywebclient extends webviewclient { @override public boolean shouldoverrideurlloading(webview view, string url) { view.loadurl(url); return true; } } public boolean onkeydown(int keycode, keyevent event){ if ((keycode == keyevent.keycode_back) && webview.cangoback()) { webview.goback(); return true; } return onkeydown(keycode, event); } }
i thankful me move forward , give bug free app. thank you.
two questions:
a) did add in manifest following permission?
<uses-permission android:name="android.permission.write_external_storage" />
b) if did , still not work, version android device?
Comments
Post a Comment