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