Android “Google Translation” popup programmatically

老子叫甜甜 提交于 2020-05-13 14:34:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!