'How to trigger “Ok google” from adb shell?

I'm trying to simulate "Ok google" from adb shell on Android O(8.0), but I couldn't find solution.

I've found that the app which shows after "Ok google" has cmp=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity. However, I couldn't launch it via adb due to below error.

$adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity
Starting: Intent { cmp=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity }
Security exception: Permission Denial: starting Intent { flg=0x10000000 cmp=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity } from null (pid=29706, uid=2000) not exported from uid 10044

java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity } from null (pid=29706, uid=2000) not exported from uid 10044
    at com.android.server.am.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1688)
    at com.android.server.am.ActivityStarter.startActivity(ActivityStarter.java:460)
    at com.android.server.am.ActivityStarter.startActivityLocked(ActivityStarter.java:277)
    at com.android.server.am.ActivityStarter.startActivityMayWait(ActivityStarter.java:920)
    at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4693)
    at com.android.server.am.ActivityManagerShellCommand.runStartActivity(ActivityManagerShellCommand.java:410)
    at com.android.server.am.ActivityManagerShellCommand.onCommand(ActivityManagerShellCommand.java:141)
    at android.os.ShellCommand.exec(ShellCommand.java:96)
    at com.android.server.am.ActivityManagerService.onShellCommand(ActivityManagerService.java:15401)
    at android.os.Binder.shellCommand(Binder.java:576)
    at android.os.Binder.onTransact(Binder.java:476)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:4341)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3040)
    at android.os.Binder.execTransact(Binder.java:681)

I expect some solution to launch the above app by adb.

  • Avoid security exception for $adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity
  • By another adb command


Solution 1:[1]

Probably need to run adb root first

> adb root
> adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.apps.gsa.staticplugins.opa.OpaActivity

Solution 2:[2]

adb root
adb shell am start -n com.google.android.googlequicksearchbox/com.google.android.apps.gsa.binaries.clockwork.assistant.AssistantActivity

worked for me on my Galaxy Watch 4 after I installed the Google App.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user3667359
Solution 2 Jayemby