zoukankan      html  css  js  c++  java
  • android中利用瀏覽器來開啟链接中含有中文的網頁问题

    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);

    -------------------------------------------
    以上做法为网上找到的方法。
    但当要开启的页面的连接为一个参数,不固定的时候,如何进行处理的。
    尝试了

    String url_Str=URLEncoder.encode(urlStr,"UTF-8");
    Uri uri = Uri.parse(url_Str);
    Intent intent = new Intent(Intent.ACTION_VIEW,uri);
    startActivity(intent);

    无法打开,因为将网址中非中文的字符也进行了编码的转换。
    解决方法为:

    String urlStr = Uri.encode(workBlock.url,":/");
    Uri u = Uri.parse(urlStr);
    intent.setData(u);
    startActivity(intent);
  • 相关阅读:
    编译java蛋疼的一小时
    最简单的Java Applet程序
    枚举任意进程内核对象句柄的方法
    RvmTranslator7.3.2
    PipeCAD
    Open CASCADE Technology 7.5.0 released
    IsoAlgo 环路处理
    OpenCASCADE STEP Color
    RvmTranslator 3D PDF in Ubuntu
    IsoAlgo Symbols
  • 原文地址:https://www.cnblogs.com/sipher/p/2594053.html
Copyright © 2011-2022 走看看