pass sms:?body=xyz to default browser in android webview

狂风中的少年 提交于 2019-12-25 01:49:33

问题


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;
        }
    }

回答1:


There is a mistake in your code.

It should be

if (url != null && url.startsWith("sms")) {

Also: If you have power over the webpage you are displaying you might want to include the phonegap library if you haven't already. That is meant to handle exactly those things.




回答2:


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);


来源:https://stackoverflow.com/questions/12661625/pass-smsbody-xyz-to-default-browser-in-android-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!