android - 如何设置 anchor 标记mailto : attribute in webview, android

标签 android android-emulator android-widget

我尝试像这样设置 anchor 标记 mailto 属性

<a href='mailto:info@company.com'>info@company.com</a>

在 WebView 中。当我在模拟器上运行该应用程序并单击它显示“不支持的操作 ..”的链接时

我如何在 android webview 中设置 mailto 属性....

谢谢

最佳答案

WebView 不支持高级 HTML 标签...您需要做的是:

  1. 为您的 webview 设置一个 webclient 并覆盖 url 加载
  2. 当您检测到带有 mailto 的链接时,请尝试发送电子邮件。

我会给你一小段代码,让你有一个想法。请记住,这只是一个基本示例,我现在无法对其进行测试:

public void onCreate(Bundle icicle) {
    // blablabla
    WebView webview = (WebView) findViewById(R.id.webview); 
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient( new YourWebClient()); 
    // blablabla
}

private class YourWebClient extends WebViewClient {     
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains("mailto")) {
            // TODO: extract the email... that's your work, LOL
            String email = "";
            sendEmail();
            return super.shouldOverrideUrlLoading(view, url);
        }
        view.loadUrl(url);
        return true;
    }
}

然后,发送邮件:

public void sendEmail(String email){
    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});

    String mySubject = "this is just if you want";
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySubject);
    String myBodyText = "this is just if you want";
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, myBodyText);
    context.startActivity(Intent.createChooser(intent, "Send mail...));
}

关于android - 如何设置 anchor 标记mailto : attribute in webview, android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3197430/

相关文章:

android - 如果我从应用程序 A 将私钥存储在 KeyStore 中,是否可以从应用程序 B 检索相同的 key ?

android - RecyclerView ItemTouchHelper 如何锁定滑动项目?

android - 我如何使用 Youwave (for android) 作为 Android Studio 的模拟器?

java - 使用加速度计、陀螺仪和指南针来计算设备在 3D 世界中的运动

android - 如何在android中动态启动和完成progressBar

android - 将第一帧视频作为android中的缩略图?

android - 如何在 Windows 中使用 Python-for-Android 创建一个包?

android - 没有 GPU 的 Android 手机上的 OpenGL ES 2.0?

android - Windows 中的 iPhone 模拟器

android - 在 Android 小部件中删除文本的子字符串