Google Translate Activity not working anymore

后端 未结 2 969
心在旅途
心在旅途 2021-01-01 02:41

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 wor

2条回答
  •  情歌与酒
    2021-01-01 03:33

    They have changed it once again:

                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);
    

提交回复
热议问题