2012-09-05 34 views
1

我在我的Android應用程序中編碼網頁的一部分時出現問題。我有一個應用程序收集網頁的一部分並將其顯示給用戶。對於這個問題,可以說我有一個帶有文本的網頁,文本下方有一張桌子,桌子下面有很多我不感興趣的垃圾。所以我選擇了使用第一個位置查看的內容。元素(例如一個獨特的標籤)和結束位置(同樣存在,一些獨特的使用InputStreamReader的一個開始/結束位置Android應用程序中的編碼問題(WebView.LoadData())

然後在我的字符串(「字符串」)我跑:

String s = Uri.encode(string); 

字符串s,然後相應地使用:

web.loadData(s, "text/html","ISO-8859-1"); 

但是這給了我一些不必要的CH ars在文本中間:「Â」出現。我試圖在字符串運行.replace(「Â」,「」);但這並不能解決問題。

我也嘗試以下操作:

web.loadData(s, "text/html", "UTF-8"); 

web.loadData(s,"text/html;utf-8",null); 

但「A」和一個或兩個「*」仍然出現?

被搜索網頁,發現:loadDataWithBaseUrl,但這並沒有解決,要麼讓我非常想索姆assistence :)

在頁面的頂部:

<html xmlns="http://www.w3.org/1999/xhtml" lang="sv-se" dir="ltr"> 

在另一頁:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-us" dir="ltr"> 

所以我有一個英文和一個瑞典頁面,但錯誤是關於這兩個網址:s。

此致敬禮!

+0

你解決了嗎?我看到了同樣的問題。 –

+0

還沒有完全解決,讓我知道你是否想出了一些東西... – erikduvet

+0

這可能是在發送方的不當使用。它只是偶爾發生,並且可能僅來自某些電子郵件客戶端。你有沒有看到任何圖案?現在,我只是在做s.replace(「\ u00A0」,「 」).replace('\ n',''); –

回答

-1

此代碼適合我。

String base64EncodedString = null; 
         try { 
          base64EncodedString = android.util.Base64.encodeToString((preString+mailContent.getBody()+postString).getBytes("UTF-8"), android.util.Base64.DEFAULT); 
         } catch (UnsupportedEncodingException e1) { 
          // TODO Auto-generated catch block 
          e1.printStackTrace(); 
         } 
         if(base64EncodedString != null) 
         { 
          wvMailContent.loadData(base64EncodedString, "text/html; charset=utf-8", "base64"); 
         } 
         else 
         { 
          wvMailContent.loadData(preString+mailContent.getBody()+postString, "text/html; charset=utf-8", "utf-8"); 
         } 
0

使用這樣的:

webview.loadData(html_content, 「text/html的;字符集= UTF-8」, 「UTF-8」);

我測試了它,它工作。