WordWarrior icon indicating copy to clipboard operation
WordWarrior copied to clipboard

google翻译的引入

Open talengu opened this issue 4 years ago • 0 comments

2012年偶然接触,喜欢这种将想法变为实际的感觉。Android研究始终在路上。

android 代码片段

google translate 的intent使用

//这种方式比较好
try {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PROCESS_TEXT);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true);
    intent.putExtra(Intent.EXTRA_PROCESS_TEXT, word_string);
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // TODO Auto-generated catch block
    Toast.makeText(getApplication(), "Sorry, No Google Translation Installed",
                   Toast.LENGTH_SHORT).show();
}
// 打开google translate
String word_string=mEwordList.get(position).getWordSpell();
try {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, word_string);
    intent.putExtra("key_text_input", word_string);
    intent.putExtra("key_text_output", "");
    intent.putExtra("key_language_from", "en");
    intent.putExtra("key_language_to", "zh-CN");
    intent.putExtra("key_suggest_translation", "");
    intent.putExtra("key_from_floating_window", false);
    intent.setComponent(new ComponentName(
        "com.google.android.apps.translate",
        //Change is here
        //"com.google.android.apps.translate.HomeActivity"));
        "com.google.android.apps.translate.TranslateActivity"));
    startActivity(intent);
} catch (ActivityNotFoundException e) {
    // TODO Auto-generated catch block
    Toast.makeText(getApplication(), "Sorry, No Google Translation Installed",
                   Toast.LENGTH_SHORT).show();
}

talengu avatar Feb 27 '20 12:02 talengu