【发布时间】:2011-12-16 19:04:38
【问题描述】:
@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 链接时,它会打开信使。出于某种原因,“http”和“?”被截断并且无法被mailto识别。相同的 mailto 链接在设备普通浏览器中完美运行。我需要获取的唯一字段是主题和正文。
【问题讨论】:
-
你能确定 mailto 链接在哪一点被破坏了吗?
-
电子邮件 从这里例如,mailto 消息正文中显示的唯一内容是“/exampletype”/ 之前的所有内容,并从 ?和失踪后。
-
对不起,我应该更清楚。 在您的代码中什么时候链接会搞砸,要弄清楚这一点,您应该使用 logcat 在所有使用它的地方显示 URL 字符串。