问题
Do you know that Google Translate now works inside any app on Android?
I'd like to get rid of extra action in my app: copy text and press "translate button".
Instead of it I'd like to show this popup window using java code. Is it possible?
回答1:
too late, may be useful for anyone regarding this question... its working for me
Intent intent = new Intent();
intent .setType("text/plain");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
intent.setAction(Intent.ACTION_PROCESS_TEXT);
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, text);
}else{
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
}
for (ResolveInfo resolveInfo : getPackageManager().queryIntentActivities(intent, 0)) {
if( resolveInfo.activityInfo.packageName.contains("com.google.android.apps.translate")){
intent.setComponent(new ComponentName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name));
startActivity(intent);
}
}
here is the referance...
回答2:
May be too late, but...
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PROCESS_TEXT);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, true);
intent.putExtra(Intent.EXTRA_PROCESS_TEXT, "hello");
startActivity(intent);
来源:https://stackoverflow.com/questions/38066936/android-google-translation-popup-programmatically