[英]“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.