java - Download file with extension pdf and ms10 inside android webView -
this question has answer here:
i'm trying download pdf , ms10 extension file inside webview below code shows "downloading" , nothing happens. should missing add intent in manifest file or other thing i'm doing wrong?
webview.setdownloadlistener(new downloadlistener() { @override 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); //notify client once download completed! request.setdestinationinexternalpublicdir(environment.directory_downloads, "name of downloadble file goes here, example: mathematics ii "); downloadmanager dm = (downloadmanager) getsystemservice(download_service); dm.enqueue(request); toast.maketext(getapplicationcontext(), "downloading file", //to notify client file being downloaded toast.length_long).show(); } });
here android manifest.xml file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.faraksoch.sagar.eroutine"> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.write_external_storage" /> <application android:allowbackup="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:roundicon="@mipmap/icon" android:supportsrtl="true" android:theme="@style/theme.appcompat.noactionbar"> <activity android:name=".mainactivity" android:configchanges="orientation" android:screenorientation="portrait" android:theme="@style/apptheme.transnav"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".updatedialog" android:theme="@style/theme.appcompat.dialog" /> <service android:name=".myfirebasemessagingservice"> <intent-filter> <action android:name="com.google.firebase.messaging_event" /> </intent-filter> </service> <service android:name=".myfirebaseinstanceidservice"> <intent-filter> <action android:name="com.google.firebase.instance_id_event" /> </intent-filter> </service> <service android:name=".updateservice" android:enabled="true" android:exported="true" /> </application>
any much appreciated.
useful library can try it. andvanced-webview
and implements it's ondownloadrequested method
@override
public void ondownloadrequested(string url, string suggestedfilename, string mimetype, long contentlength, string contentdisposition, string useragent) { // file available download // either handle download or use code below if (advancedwebview.handledownload(this, url, suggestedfilename)) { // download handled } else { // download couldn't handled because user has disabled download manager app on device // todo show notice user } }
Comments
Post a Comment