通过手机短信:身体= XYZ到默认的浏览器在Android中的WebView [英] pass sms:?body=xyz to default browser in android webview

查看:261
本文介绍了通过手机短信:身体= XYZ到默认的浏览器在Android中的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的web视图对于显示HTML页面
页面有像

链接

< A HREF =短信:身体XYM =>转发并LT; / A>

这工作正常,在歌剧和默认浏览器
但使用的WebView不工作在应用程序

我尝试下面code,但不工作

 公共布尔shouldOverrideUrlLoading(的WebView myWebView,字符串URL){
        如果(URL = NULL&放大器;!&安培; url.startsWith(短信:?)){
            。myWebView.getContext()startActivity(新意图(Intent.ACTION_VIEW,Uri.parse(URL)));
            返回true;
        }其他{
            返回false;
        }
    }


解决方案

您需要创建正确的类型单独的SMS意图,给短信写权限的应用程序。

 意图smsIntent =新意图(Intent.ACTION_VIEW);
smsIntent.setType(vnd.android-DI​​R / MMS短信);
smsIntent.putExtra(地址,从URL报废电话号码);
smsIntent.putExtra(SMS_BODY,消息的身体网址报废);
startActivity(smsIntent);

I Am Using Webview For Display html page page have link like

<a href="sms:body=xym">Forward</a>

Which Working Fine In Opera And Default Browser But Not Working In Application using webview

I Try below code but not working

    public boolean shouldOverrideUrlLoading(WebView myWebView, String url) {
        if (url != null && url.startsWith("sms:?")) {
            myWebView.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        } else {
            return false;
        }
    }

解决方案

You need to create a separate SMS intent with proper type and give SMS write permissions to the application.

Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "Phone number scrapped from url");
smsIntent.putExtra("sms_body","Body of Message scrapped from url");
startActivity(smsIntent);

这篇关于通过手机短信:身体= XYZ到默认的浏览器在Android中的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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