繁体   English   中英

android webview mailto链接中的“ http”和“?”被截断

[英]“http” and “?” are getting cutoff in android webview mailto links

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

尝试将mailto添加到Webview应用程序。 当您运行该应用程序并单击mailto链接时,它将打开Messenger。 由于某些原因,“ http”和“?” 被切断并且不被mailto识别。 相同的mailto链接可在设备普通浏览器中完美运行。 我需要获得的唯一领域是主题和身体。

不错的选择:确保当他们到达MailTo解析代码时,mailto链接主题/正文字段中的任何内容都转义为URL(没有文字斜杠,“&”等)。 ? ”特别是在页眉保留字符邮寄地址RFC

那不是

mailto://...subject=http://foo.com?x=y

但尝试

mailto://...subject=http%3A%2F%2Ffoo.com%3Fx%3Dy

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM