Webview email link (mailto)

前端 未结 3 765
暖寄归人
暖寄归人 2021-01-31 15:39

I have a view and view the site has malito code to send email. When I open the link opens in an error. I want that when I open the link opens Gmail app or another email applic

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 16:32

    You should update your's WebViewClient with the following:

    @SuppressWarnings("deprecation") 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        proceedUrl(view, Uri.parse(url))
        return true; 
    } 
    
    @TargetApi(Build.VERSION_CODES.N)
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        proceedUrl(view, request.getUrl());
        return true; 
    }
    
    private void proceedUrl(View view, Uri uri){  
        if (uri.toString().startsWith("mailto:")) {
            startActivity(new Intent(Intent.ACTION_SENDTO, uri));
        } else if (uri.toString().startsWith("tel:")) {
            startActivity(new Intent(Intent.ACTION_DIAL, uri));
        } else { 
            view.loadUrl(uri.toString());
        } 
    } 
    

提交回复
热议问题