谷歌翻译活动不工作了 [英] Google Translate Activity not working anymore
问题描述
我写的通过 Intent.ACTION_VIEW
调用谷歌翻译Android应用程序。
问题是,调用谷歌翻译应用程序不工作了,虽然它一次。
I wrote a program that invokes Google Translator android application via Intent.ACTION_VIEW
.
The problem is that invoking the Google Translator App does not work anymore, although it did once.
在code等同于这里给出的code:
The code is identical to the code given here:
<一个href=\"http://stackoverflow.com/questions/18082118/returning-translated-text-from-google-translate-activity\">Returning从谷歌翻译的文本翻译活动
(是的,我想通过code来代替我的code,谷歌翻译应用程序的行为,如果它没有收到任何数据。)
(yes, I tried to replace my code by that code, the Google Translator App behaves as if it does not receive any data.)
目前我不能指定文字和两种语言。我能做的最好的就是用 ACTION_SEND
,但却忽视了两种语言:
Currently I cannot specify the text and the two languages. The best I can do is to use ACTION_SEND
, but it ignores the two languages:
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, "What is going on?");
i.putExtra("key_text_input", "What time is it?");
i.putExtra("key_text_output", "");
i.putExtra("key_language_from", "en");
i.putExtra("key_language_to", "es");
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.translation.TranslateActivity"));
实际发生的事情,当我跑这code是:这是怎么回事的谷歌翻译问我,如果我想从英语翻译和翻译法国
What actually happened when I ran this code was: the Google Translator asked me if I want to translate from English and translated "What is going on?" to French.
所以:我如何通过语言的谷歌翻译应用程序现在
So: how do I pass the languages to the Google Translate App now?
推荐答案
他们再一次改变它:
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 = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setPackage("com.google.android.apps.translate");
Uri uri = new Uri.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);
这篇关于谷歌翻译活动不工作了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!