首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"http“和"?”在android webview邮件链接中被截断

"http“和"?”在android webview邮件链接中被截断
EN

Stack Overflow用户
提问于 2011-10-28 03:18:12
回答 1查看 816关注 0票数 1
代码语言:javascript
复制
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.main);

    // Don't create another webview reference here,
    // just use the one you declared at class level.
    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://www.example.com");

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String     description, String failingUrl)
        {
        // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
          if(url.startsWith("mailto:")){
              MailTo mt = MailTo.parse(url);
              Intent i = newEmailIntent(HelloWorld.this, mt.getBody(), mt.getSubject());
              startActivity(i);
              view.reload();
              return true;
        }

        view.loadUrl(url);
        return true;
    }

   });
}
public static Intent newEmailIntent(Context context, String body, String subject ) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {});
    intent.putExtra(Intent.EXTRA_TEXT, body);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.setType("rfc2368/html");
    return intent;
   }
} 

正在尝试将邮件添加到webview应用程序。当您运行应用程序并单击mailto链接时,它会打开messenger。出于某种原因,"http“和"?”被截断并且不能被邮件识别。同样的mailto链接在设备的普通浏览器中也能完美工作。我唯一需要获取的字段是subject和body。

EN

回答 1

Stack Overflow用户

发布于 2011-10-28 04:18:56

好办法:确保mailto链接主题/正文字段中的任何内容都是URL转义的(没有文字斜杠、&符号等)当他们得到MailTo解析代码的时候。特别地,"?“是Mailto RFC中头的保留字符。

也就是说,不

代码语言:javascript
复制
mailto://...subject=http://foo.com?x=y

而不是试着

代码语言:javascript
复制
mailto://...subject=http%3A%2F%2Ffoo.com%3Fx%3Dy
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7921151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档