Android: Downloading in webview not working in oreo, it force closes in Oreo devices

前端 未结 2 691
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-23 08:51

Download manager code is not working in Android WebView for Oreo devices, but it\'s working well for older versions In case other than Oreo devices it toasts \"down

相关标签:
2条回答
  • 2021-01-23 09:20

    This is the code what I figured it out and working for me.

    NOTE: code is been executed in a fragment, for the main activity remove getActivity(). in manifest give the permission

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    Tutorial for permision prompt

    CODE:

    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));
                if(Build.VERSION.SDK_INT <= 26 ){
                    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));
                }
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!
    
                DownloadManager dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
                dm.enqueue(request);
                Toast.makeText(getActivity().getApplicationContext(), "Downloading File", //To notify the Client that the file is being downloaded
                        Toast.LENGTH_LONG).show();
    
    
            }
    
    
    
        });
    
    0 讨论(0)
  • 2021-01-23 09:25

    Try to remove the preloading of fonts by removing

    <meta-data 
    android:name="preloaded_fonts" 
    android:resource="@array/preloaded_fonts" />  
    

    Source Webview in Oreo not working

    0 讨论(0)
提交回复
热议问题