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


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

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

即可以開啟網頁,但是若要在url後面加上參數則可能會造成中文亂碼問頭發生

解決方法為將參數利用URLEncoder.encode轉成utf8再傳送即可


String urlStr = "http://www.google.com.tw/search?test="+URLEncoder.encode("測試","UTF-8");

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

 


arrow
arrow
    全站熱搜

    狼翔月影 發表在 痞客邦 留言(1) 人氣()