How to start Google Assistant programmatically?

前端 未结 2 737
悲&欢浪女
悲&欢浪女 2020-12-11 18:16

I have tried every simple combo I have found but not sure how to do this. I even tried to simulate the home long press but you get google now voice, lookint at logcat it sho

相关标签:
2条回答
  • 2020-12-11 18:59

    This works:

    startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    
    0 讨论(0)
  • 2020-12-11 19:14

    So I've been trying to do the same thing, and just discovered something when I'm trying to launch the Assistant with an Intent like this:

    Intent launchIntent = new Intent(Intent.ACTION_VIEW);
            launchIntent.setPackage("com.google.android.googlequicksearchbox");
            launchIntent.setClassName("com.google.android.googlequicksearchbox", "com.google.android.apps.gsa.staticplugins.opa.OpaActivity");
    startActivity(launchIntent);
    

    Although this doesn't throw an ActivityNotFoundException, it does throw a Permission Denial. This is shown to happen because Google Assistant must be launched from the googlequicksearchbox package from above. Hopefully this will change when/if they release an API for it. Fingers crossed.

    0 讨论(0)
提交回复
热议问题