How to use google translator app

前端 未结 6 1677
你的背包
你的背包 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条回答
  •  忘了有多久
    2021-02-02 02:27

    I have the same problem. Initially, I tried to use Google Translate Ajax API, but since Google have deprecated API version 1 and make version 2 as paid service, my code stops working. Then, I decompiled Google Translate App, looked into the Smali code and got some hint about the logic inside it. Use this code, it works for me:

    private void callGoogleTranslateApps(String word, String fromLang, String toLang) {
        Intent i = new Intent();
    
        i.setAction(Intent.ACTION_VIEW);
        i.putExtra("key_text_input", word);
        i.putExtra("key_text_output", "");
        i.putExtra("key_language_from", fromLang);
        i.putExtra("key_language_to", toLang);
        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.TranslateActivity"));
        startActivity(i);
    }
    

提交回复
热议问题