的WebView"邮寄地址:"链接和放大器; "电话:"使用Intent.ACTION_VIEW环节的工作,但我怎么添加独特的主题,即对"邮寄地址:"链接 [英] Webview "mailto:" link & "tel:" link work using Intent.ACTION_VIEW, but how do I add unique Subject ie for "mailto:" link

查看:225
本文介绍了的WebView"邮寄地址:"链接和放大器; "电话:"使用Intent.ACTION_VIEW环节的工作,但我怎么添加独特的主题,即对"邮寄地址:"链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得理所应当使用下面的code这个工作。所有的HTTP URL,因为他们应该在web视图中打开电话:链接打开,因为它应该在拨号程序,然后电子邮件地址:链接打开,因为它应该在电子邮件客户端

I've got this working as it should using the following code. All http urls open as they should within the webview, "tel:" link opens as it should in dialler, and "mailto:" link opens as it should in email client.

但我的问题是,我该如何改变电子邮件地址的主题链接到不同的东西,而不是它的pre定义的主题。我猜应该有2个独立的意图,1电话:链接&安培; 1至mailto:链接。我根本不知道如何把code到下面的shouldOverrideUrlLoading方法。或者,也许我用什么我需要错误的方法。

But my problem is how do I change the subject of the "mailto:" link to something different instead of its pre-defined subject. I'm guessing there should be 2 seperate intents, 1 for "tel:" link & 1 for "mailto:" link. I simply don't know how to put the code into the shouldOverrideUrlLoading method below. Or maybe I'm using the wrong method for what I require.

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if( url.startsWith("http:") || url.startsWith("https:") ) {
                return false;
            }

            // Otherwise allow the OS to handle it
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url));
            startActivity(intent);
            return true;
        }

我设法让我自己的主题为至mailto:意图工作,但没有电话:列入code链接。那么,如何可以做到既加用我自己的主题在电子邮件地址:链接

I managed to get my own subject "mailto:" working with Intent, but without the "tel:" link included in code. So how can I do both plus use my own subject in "mailto:" link?

任何意见或建议,将大大AP preciated!

Any ideas or suggestions will be much appreciated!

推荐答案

这是我的解决方案和放大器;它为我工作。我希望它能帮助其他人有同样的问题我了。

This is my solution & it works for me. I hope it helps anyone else with the same issue I had.

@Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if( url.startsWith("http:") || url.startsWith("https:") ) {
                return false;
            }

            // Otherwise allow the OS to handle it
            else if (url.startsWith("tel:")) { 
                Intent tel = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); 
                startActivity(tel);
                return true;
            }
            else if (url.startsWith("mailto:")) {
                String body = "Enter your Question, Enquiry or Feedback below:\n\n";
                Intent mail = new Intent(Intent.ACTION_SEND);
                mail.setType("application/octet-stream");
                mail.putExtra(Intent.EXTRA_EMAIL, new String[]{"email address"});
                mail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                mail.putExtra(Intent.EXTRA_TEXT, body);
                startActivity(mail);
                return true;
                }
            return true;
        }

这篇关于的WebView"邮寄地址:"链接和放大器; "电话:"使用Intent.ACTION_VIEW环节的工作,但我怎么添加独特的主题,即对"邮寄地址:"链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆