如何在Android中的webview中显示电子邮件内容?

时间:2015-12-28 13:32:14

标签: android email webview

我想在android中的webview中显示电子邮件内容,我可以在textview中显示来自电子邮件,电子邮件,日期等,但我无法显示内容 这是我正在做的但是在webview中找不到邮件内容,请帮帮我。

private boolean textIsHtml = false;


private String getText(Part p){
    try {
        if (p.isMimeType("text/*")) {
            String s = (String)p.getContent();
            textIsHtml = p.isMimeType("text/html");
            return s;
        }
    } catch (MessagingException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        if (p.isMimeType("multipart/alternative")) {
            // prefer html text over plain text
            Multipart mp = (Multipart)p.getContent();
            String text = null;
            for (int i = 0; i < mp.getCount(); i++) {
                Part bp = mp.getBodyPart(i);
                if (bp.isMimeType("text/plain")) {
                    if (text == null)
                        text = getText(bp);
                    continue;
                } else if (bp.isMimeType("text/html")) {
                    String s = getText(bp);
                    if (s != null)
                        return s;
                } else {
                    return getText(bp);
                }
            }
            return text;
        } else if (p.isMimeType("multipart/*")) {
            Multipart mp = (Multipart)p.getContent();
            for (int i = 0; i < mp.getCount(); i++) {
                String s = getText(mp.getBodyPart(i));
                if (s != null)
                    return s;
            }
        }
    } catch (MessagingException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
    }

   //Setting Content
wv=(WebView)findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
 wv.getSettings().setLoadWithOverviewMode(true);
 //default browser
 wv.setWebChromeClient(new WebChromeClient() {

 });

   wv.loadData(getText(message),"text/html", "UTF-8");

这是我的日志,我得到了异常

 12-29 16:07:43.876: I/Timeline(15130): Timeline: Activity_launch_request id:com.minio time:313995100
12-29 16:07:43.926: W/art(15130): Attempt to remove local handle scope entry from IRT, ignoring
12-29 16:07:43.926: W/AwContents(15130): onDetachedFromWindow called when already detached. Ignoring
12-29 16:07:43.926: W/System.err(15130): javax.mail.FolderClosedException
12-29 16:07:43.936: W/System.err(15130):    at com.sun.mail.imap.IMAPMessage.getProtocol(IMAPMessage.java:149)
12-29 16:07:43.936: W/System.err(15130):    at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1262)
12-29 16:07:43.936: W/System.err(15130):    at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:443)
12-29 16:07:43.936: W/System.err(15130):    at javax.mail.internet.MimeBodyPart.isMimeType(MimeBodyPart.java:1059)
12-29 16:07:43.936: W/System.err(15130):    at javax.mail.internet.MimeMessage.isMimeType(MimeMessage.java:965)
12-29 16:07:43.936: W/System.err(15130):    at com.minio.EmailView.getText(EmailView.java:49)
12-29 16:07:43.936: W/System.err(15130):    at com.minio.EmailView.onCreate(EmailView.java:102)
12-29 16:07:43.936: W/System.err(15130):    at android.app.Activity.performCreate(Activity.java:6221)
12-29 16:07:43.936: W/System.err(15130):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
12-29 16:07:43.936: W/System.err(15130):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)
12-29 16:07:43.936: W/System.err(15130):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2723)
12-29 16:07:43.936: W/System.err(15130):    at android.app.ActivityThread.access$900(ActivityThread.java:172)
12-29 16:07:43.936: W/System.err(15130):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
12-29 16:07:43.936: W/System.err(15130):    at android.os.Handler.dispatchMessage(Handler.java:102)
12-29 16:07:43.936: W/System.err(15130):    at android.os.Looper.loop(Looper.java:145)
12-29 16:07:43.936: W/System.err(15130):    at android.app.ActivityThread.main(ActivityThread.java:5832)
12-29 16:07:43.936: W/System.err(15130):    at java.lang.reflect.Method.invoke(Native Method)
12-29 16:07:43.936: W/System.err(15130):    at java.lang.reflect.Method.invoke(Method.java:372)
12-29 16:07:43.936: W/System.err(15130):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
12-29 16:07:43.936: W/System.err(15130):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
12-29 16:07:43.936: D/Activity(15130): performCreate Call secproduct feature valuefalse
12-29 16:07:43.936: D/Activity(15130): performCreate Call debug elastic valuetrue
12-29 16:07:44.066: I/Timeline(15130): Timeline: Activity_idle id: android.os.BinderProxy@187856 time:313995291
12-29 16:07:56.896: I/art(15130): Debugger is no longer active
12-29 16:07:56.906: W/art(15130): Suspending all threads took: 8.982ms

0 个答案:

没有答案