Android webview download any files or mp3 files using url link -
i creating webview app, use download .mp3 files mobile phone using url link within webview. im newbie in arena. many example ive seen, yet dint understand because bit different current code. got confused. based on code given..what code need input user can click on url link within webview download files .mp3 files internal or external memory?
(activitymain.xml) <webview android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerhorizontal="true" android:layout_centervertical="true" /> (androidmanifest.xml) <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.access_download_manager"/> (mainactivity.java) webview = (webview) findviewbyid(r.id.webview); websettings websettings = webview.getsettings(); websettings.setjavascriptenabled(true); webview.setwebviewclient(new webviewclient()); webview.loadurl("weblink");
had seen this question? suppose should use downloadlistener file downloading:
webview.setdownloadlistener
:
registers interface used when content can not handled rendering engine, , should downloaded instead. replace current handler.
so, code should this:
webview.setdownloadlistener(new downloadlistener() { public void ondownloadstart(string url, string useragent, string contentdisposition, string mimetype, long contentlength) { intent = new intent(intent.action_view); i.setdata(uri.parse(url)); startactivity(i); } });
Comments
Post a Comment