Google Translate Activity Not Working Anymore
Solution 1:
They have changed it once again:
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.google.android.apps.translate");
intent.putExtra(Intent.EXTRA_TEXT, text);
UPDATE: It is possible to pass the languages if you pack the text and the languages into an URI:
intent = newIntent();
intent.setAction(Intent.ACTION_VIEW);
intent.setPackage("com.google.android.apps.translate");
Uriuri=newUri.Builder()
.scheme("http")
.authority("translate.google.com")
.path("/m/translate")
.appendQueryParameter("q", "c'est l'meunier Mathurin qui caresse les filles au tic-tac du moulin")
.appendQueryParameter("tl", "pl") // target language
.appendQueryParameter("sl", "fr") // source language
.build();
//intent.setType("text/plain"); //not needed, but possible
intent.setData(uri);
Solution 2:
UPDATE:
The following code works with the new version of Google Translate Application:
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, "What is going on?");
i.putExtra("key_text_input", "Oh my God! What is going on here?");
//i.putExtra("key_text_output", "");
i.putExtra("from", "en");
i.putExtra("to", "zh-CN");
//i.putExtra("key_suggest_translation", "");
//i.putExtra("key_from_floating_window", false);
i.setComponent(new ComponentName("com.google.android.apps.translate",
"com.google.android.apps.translate.HomeActivity"));
As you can see, this is the standard ACTION_SEND with additional parameters "to" and "from".
There's a gotcha: "key_text_input" takes preference over Intent.EXTRA_TEXT, and "to" and "from" work only with "key_text_input".
If you have an impression that no data is passed (at all), maybe it is because you use 3-character language codes instead of 2-character ones. But the codes for Chinese are zh-CN and zh-TW.
My previous post:
The action and the parameter names have changed.
Intenti=newIntent();
i.setAction("com.google.android.apps.translate.action.QUERY");
i.putExtra("key_text_input", "Oh my God! What is going on?");
i.putExtra("key_text_output", "");
i.putExtra("from", "en");
i.putExtra("to", "zh-CN");
i.putExtra("key_suggest_translation", "");
i.putExtra("key_from_floating_window", false);
i.setComponent(newComponentName("com.google.android.apps.translate",
"com.google.android.apps.translate.translation.TranslateActivity"));
Solution 3:
The other answers will open Google Translate app as a full-screen activity. I wanted to open it as a floating window above my current app.
Turns out you can do this with the Intent action of "android.intent.action.PROCESS_TEXT" e.g.
translateIntent.setComponent(newComponentName(
"com.google.android.apps.translate",
"com.google.android.apps.translate.QuickTranslateActivity"
));
translateIntent.setAction(Intent.ACTION_PROCESS_TEXT);
translateIntent.putExtra(Intent.EXTRA_PROCESS_TEXT, textToTranslate);
Note: I didn't actually use this method as I pulled the intent of the system context menu using onActionStarted but I sniffed the intent for you so I don't see why this wouldn't work if created manually.
Post a Comment for "Google Translate Activity Not Working Anymore"