Android go to url 中文亂碼解決方法

2010年10月5日 星期二

android 中,利用瀏覽器來開啟網頁的做法為

String url_Str = "http://www.google.com.tw";

Uri uri = Uri.parse(url_Str);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);

以上程式即可以開啟網頁,但是若要在url後面加上參數則可能會造成中文亂碼問頭發生,解決方法為將參數利用URLEncoder.encode轉成utf8再傳送即可


String url_Str="http://www.yahoo.com/search?test="+URLEncoder.encode("字串","UTF-8");

Uri uri = Uri.parse(url_Str);
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);

0 意見:

張貼留言

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP