简体   繁体   English

以编程方式向Android“ Google翻译”弹出窗口

[英]Android “Google Translation” popup programmatically

Do you know that Google Translate now works inside any app on Android? 您知道Google翻译现在可以在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. 取而代之的是,我想使用Java代码显示此弹出窗口。 Is it possible? 可能吗?

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

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... 是参考...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM