Search code examples
androidandroid-intentintentfilter

Android Google Translate QuickTranslateActiviy - Intent extra issue


I want to use the QuickTranslateActiviy and I have tried this

Intent i = new Intent();
i.setAction(Intent.ACTION_PROCESS_TEXT);        
i.addCategory(Intent.CATEGORY_DEFAULT);     
i.putExtra(Intent.EXTRA_TEXT,"String");     
i.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
i.setComponent(new ComponentName("com.google.android.apps.translate","com.google.android.apps.translate.QuickTranslateActivity"));
startActivity(i);

and It just keep showing the toast that could not find text. But the manifest of the Google translate here show that it accept plain text had anyone try that before?Or am I doing it in a wrong way?


Solution

  • Tactically, you are using the wrong extra name. It should be EXTRA_PROCESS_TEXT or EXTRA_PROCESS_TEXT_READONLY, not EXTRA_TEXT.

    Strategically, your implementation will break any time that the Google Translate app refactors their code or otherwise changes the fully-qualified class name of the activity.