2016-08-30 11 views
0

私は深いリンクを使って作業しています。ウェブからIntentFilter経由でAndroidに日本語文字列を渡すときに問題が発生しました。いくつかのコードがあります。インテントアンドロイド自動エンコード文字列

は、HTMLコードとのWebViewの初期化:

String encode = URLEncoder.encode("namhv://category?category_name=レビュー", "UTF-8"); 
    Log.e(TAG, "Url Encode: " + encode); 
    Log.e(TAG, "Url Decode:" + URLDecoder.decode(encode, "UTF-8")); 
    WebView webView = (WebView) findViewById(R.id.wv_content); 
    webView.getSettings().setJavaScriptEnabled(true); 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 
     WebView.setWebContentsDebuggingEnabled(true); 
    } 

    String html = "<html><body>\n" + 
      "<br><a href=\"" + encode + "\">test go tab</a><br>" + 
      "</body></html>"; 
    Log.e(TAG, html); 
    webView.loadData(html, "text/html", "UTF-8"); 

ハンドル意図:

public boolean handleDeepLinkEvent(Intent intent) throws UnsupportedEncodingException { 
    if (intent.getData() != null) { //deep link 
     String cateName = intent.getDataString(); 
     Log.e(TAG, cateName); 
     Log.e(TAG, URLDecoder.decode(cateName, "UTF-8")); 
     return true; 

    } 
    return false; 
} 

(1)原点文字列:namhv://カテゴリカテゴリ名=レビュー

(2)UTF8でエンコードした後の文字列:namhv%3A%2F%2Fcategory%3Fcategory_name%3D%E3%83%AC%E3%83%93%E3%83%A5%E3%83%BC

(3)インテントで受信した文字列:namhv:// category?カテゴリ名=%C3%A3%C6%92%C2%AC%C3%A3%C6%92%E2%80%9C%C3%A3%C6 UTF8で解読された後の文字列:namhv:// category?category_name =ãƒãƒƒ "ヌ¼¼私の期待通りに(2)と(3)は同じであり、(1)と(4)は同じである。しかし、私はIntentFilter経由でAndroidが文字列を渡すときに何をするのか分からない。

答えて

0

この問題は

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

webView.loadDataWithBaseURL(null, htmlString, "text/html", "utf-8", null); 

によってrepleaceによって解決されます
関連する問題