1
我正在創建一個翻譯器應用程序,我從android支持的語音識別器獲取輸入文本。例如:印地文,中國等,現在我想建立這樣的查詢 -從Android中的谷歌翻譯器讀取任何語言字符串
public JSONObject getTranslatedText() {
StringBuilder sb = new StringBuilder();
String http = "https://translation.googleapis.com/language/translate/v2?key=xyz";
JSONObject response = null;
String json = "";
HttpURLConnection urlConnection = null;
try {
URL url = new URL(http);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.connect();
String line1 = "{\n" + " 'q': '" + inputString + "',\n" + " 'target': '" + targetcodeString + "'\n" + "}";
DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream());
out.writeBytes(line1);
out.flush();
out.close();
BufferedReader br = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
json = sb.toString();
response = new JSONObject(json);
} catch (MalformedURLException e) {
} catch (IOException e) {
} catch (JSONException e) {
} finally {
if (urlConnection != null) urlConnection.disconnect();
}
return response;
}
問題是,它沒有正確編碼和我得到的輸出這樣的 - 例子:對於一個字「你怎麼樣你「in印度即」क्याहाल「as 9 & HG 08 * E
請問我能否得到一些幫助。提前致謝。
嘗試使用'yourTextView.setText(Html.fromHtml(「your chars」))設置unicode字符;' – ELITE
它不工作。試過了。 –
check [display-different-languages-in-set-in-textview](https://stackoverflow.com/questions/15462171/display-different-languages-in-set-in-textview)and [urdu-font- in-textview](https://stackoverflow.com/questions/15492398/urdu-font-in-textview) – ELITE