How to use google translator app

前端 未结 6 1612
你的背包
你的背包 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

    OMG! They have changed it once again! They have made it look more reasonable, but not compatible with the previous version.

    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!");
    i.putExtra("from", "en");
    i.putExtra("to", "zh-CN");
    i.setComponent(new ComponentName("com.google.android.apps.translate",
                    "com.google.android.apps.translate.HomeActivity"));
    

    Looks like this is a SEND intent with two additional (BTW, optional) 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".

    For people that change the API with each new version it may look only reasonable to rename "key_text_input" to, say, just "text_input", so we will look forward to the next release...

    To be on the safe side, I'd propose to set both Intent.EXTRA_TEXT and "key_text_input" to the same value.

提交回复
热议问题