Open application in WebView

I have an app on WebView. When I click on it, nothing happens. I know a way to open an application in WebView, but the solution is state based. Is there any solution to open it without setting a condition, because the number of extension attachments is supported in my application. I do not want the application to be downloaded.
This is what I'm doing right now, and these are just a few extensions:

if ((url.contains(".pdf") || url.contains(".xml") || url.contains(".xlsx") || url.contains(".docx") || url.contains(".ppt"))) {
                            url = org.apache.commons.lang3.StringUtils.join("http://docs.google.com/gview?embedded=true&url=", url);
                            browser.loadUrl(url);
                        }
+4
source share
1 answer

, , , . Android- Android :

1: webviewclient URL:

- , URL- , URL-.

webview.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url){
        // you can try to open the url, you can also handle special urls here
        view.loadUrl(url);
        return false; // do not handle by default action
   }
});

, , , , - :

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
       // handle different requests for different type of files
       // Download url when it is a music file
       if (url.endsWith(".mp3")) {
           Uri source = Uri.parse(url);
           DownloadManager.Request mp3req = new DownloadManager.Request(source);
           // appears the same in Notification bar while downloading
           mp3req.setDescription("Downloading mp3..");
           mp3req.setTitle("song.mp3");
           if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
               mp3req.allowScanningByMediaScanner();
               mp3req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
           }                   
           mp3req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "song.mp3");
           DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
           manager.enqueue(mp3req);
      }
      else if(url.endsWith(".something")) {
          // do something else
      }
      //or just load the url in the web view
      else view.loadUrl(url);
      return true;                
}

2: :

, . , .

mWebView.setDownloadListener(new DownloadListener() {
    public void onDownloadStart(String url, String userAgent,
                String contentDisposition, String mimetype,
                long contentLength) {
        //do whatever you like with the file just being downloaded

    }
});

,

, WebView, WebView, WebView . hardware acceleration html5. : SVG Android 3.0. , WebView, .

WebView : https://developer.chrome.com/multidevice/webview/overview

,

+2

Source: https://habr.com/ru/post/1607961/


All Articles