java - Read any Language String from Google Translator in Android -


i creating translator app getting input text android supported voice recognizer. example : hindi, chinese, etc. want build query -

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) {      } {         if (urlconnection != null) urlconnection.disconnect();      }     return response; } 

the problem is not encoding , getting output - example: word "how you" in hindi i.e "क्या हाल" 9 & hg 08 * e

can please. in advance.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -