简体   繁体   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;
   }
} 

Trying to add a mailto to a webview application. 尝试将mailto添加到Webview应用程序。 When you run the application and click a mailto link it opens up the messenger. 当您运行该应用程序并单击mailto链接时,它将打开Messenger。 For some reason "http" and "?" 由于某些原因,“ http”和“?” are getting cut off and not recognized by the mailto. 被切断并且不被mailto识别。 The same mailto link works perfect in devices normal browser. 相同的mailto链接可在设备普通浏览器中完美运行。 The only field I need to get are subject and body. 我需要获得的唯一领域是主题和身体。

Good bet: Make sure any of the content in the mailto link subject/body fields are URL escaped (no literal slashes, ampersands, etc.) when they get to the MailTo parsing code. 不错的选择:确保当他们到达MailTo解析代码时,mailto链接主题/正文字段中的任何内容都转义为URL(没有文字斜杠,“&”等)。 " ? " in particular is a reserved character for headers in the Mailto RFC . ? ”特别是在页眉保留字符邮寄地址RFC

That is, not 那不是

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

but instead try 但尝试

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

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

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