java - Download progress Bar absent in Notification when Downloading file inside Webview -
i"m able download file webview doesn't show me progress bar in notification panel. if go download directory of ext storage, can see file.
how can make download progress bar visible. appreciated.
here code library initiate download
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.setmimetype(mimetype); //------------------------cookie!!------------------------ string cookies = cookiemanager.getinstance().getcookie(url); request.addrequestheader("cookie", cookies); //------------------------cookie!!------------------------ request.addrequestheader("user-agent", useragent); request.setdescription("downloading file..."); request.settitle(urlutil.guessfilename(url, contentdisposition, mimetype)); request.allowscanningbymediascanner(); request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed); request.setdestinationinexternalpublicdir(environment.directory_downloads, urlutil.guessfilename(url, contentdisposition, mimetype)); downloadmanager dm = (downloadmanager) getsystemservice(download_service); dm.enqueue(request); toast.maketext(getapplicationcontext(), "downloading file", toast.length_long).show(); } }); and manifest file is
<?xml version="1.0" encoding="utf-8"?> <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 largely appreciated. , records , download link generated google drive
and main activity file starts with:
public class mainactivity extends appcompatactivity { boolean doublebacktoexitpressed = false; private textview textview; private bottombar bottombar; @override protected void oncreate(@nullable bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_main); view decorview = getwindow().getdecorview(); int uioptions = view.system_ui_flag_fullscreen; decorview.setsystemuivisibility(uioptions);
if have file downloaded file sdcard or downloaded directory.
then open file in default pdf viewer of application see below
public static void openpdffileasintent(context context, file file) { intent target = new intent(intent.action_view); target.setdataandtype(uri.fromfile(file), "application/pdf"); target.setflags(intent.flag_activity_clear_top); intent intent = intent.createchooser(target, "open file"); try { context.startactivity(intent); } catch (activitynotfoundexception e) { toast.maketext(context, "please add pdf viewer application", toast.length_long).show(); } } usage:
openpdffileasintent(mainactivity.this,file);
Comments
Post a Comment