Yandex
Yandex
Yandex
//Declare Context
Context ctx;
String resultString;
//Set Context
TranslatorBackgroundTask(Context ctx){
this.ctx = ctx;
}
@Override
protected String doInBackground(String... params) {
//String variables
String textToBeTranslated = params[0];
String languagePair = params[1];
String jsonString;
try {
//Set up the translation call URL
String yandexKey =
"trnsl.1.1.20171226T121459Z.08a8183263f03572.8c5cff0151c8ebcd9370fe18f8fd51b474f9b3
bc";
String yandexUrl =
"https://translate.yandex.net/api/v1.5/tr.json/translate?key=" + yandexKey
+ "&text=" + textToBeTranslated + "&lang=" + languagePair;
URL yandexTranslateURL = new URL(yandexUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String result) {
translated.setText(resultString);
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}