How to use google translator app

前端 未结 6 1688
你的背包
你的背包 2021-02-02 02:14

I coded program about dictionary sentence and I want to have function to go to \"google translator\" application in my app

How can I use it , Should I import anything?

6条回答
  •  萌比男神i
    2021-02-02 02:39

    Phi Van Ngoc's answer was fantastic, thanks for that.

    However it didn't work initially for me and after investigating the Translate apk, it looks like they've modified their file structure slightly, so the intent ComponentName should now be:

    i.setComponent(
        new ComponentName(
            "com.google.android.apps.translate",
            "com.google.android.apps.translate.translation.TranslateActivity"));
    

    The difference is that "translation" has been added before "TranslateActivity"

    So my final version, including hard-coded translation from Spanish to English, is:

    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.putExtra("key_text_input", "Me gusta la cerveza");
    i.putExtra("key_text_output", "");
    i.putExtra("key_language_from", "es");
    i.putExtra("key_language_to", "en");
    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"));
    startActivity(i);
    

提交回复
热议问题