I'm trying to launch a youtube search from ADB (from another device on raspbian).
So I want to launch youtube app then launch a search "test"
I can launch youtube app using this : shell monkey -p com.google.android.youtube.tv -c android.intent.category.LAUNCHER 1
But I couldn't find how to launch the search. I guess it is using intent.action.search...
What would be the right code ? And do you have any link explaining how to use the adb and intent ?
I couldn't find any explaining it easily,
Thanks,
1st approach
As I don't have the android tv and hence youtube tv app. I will tell it with the help of the youtube app that comes preinstalled in mobile.
Intent used to open search on com.google.android.youtube which comes preinstalled on android phones is
com.google.android.youtube.action.open.search
You can find this intent in android manifest of the app.
Please take extra care to look at android:exported in manifest.
Here is the complete command syntax to open the app and open search bar.
adb shell am start -a [intent action name] -n [activity name]
To get the activity name in any app, go to that app and click on that activity and then run this
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
Here is what I got in my case
mCurrentFocus=Window{a4d41d0 u0 com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity}
mFocusedApp=AppWindowToken{31adc14 token=Token{c0a51f0 ActivityRecord{c314a33 u0 com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity t283}}}
In my case the activity is
com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity
Hence to open the search bar I will type
adb shell am start -a com.google.android.youtube.action.open.search -n com.google.android.youtube/com.google.android.apps.youtube.app.WatchWhileActivity
Then to type in anything there are many options, one of them is by sending keys through virtual keyboard like
adb shell input text "hello"
To know about more option, you can type
adb shell input text help
2nd Approach
There is another approach which is based on clicking the search bar after you open your activity using am start.
Here first you need to know the coordinates of the search bar by clicking on the search bar and capturing its coordinates using
adb shell getevent -l
and then send touches using
adb shell input tap [x_coordinate] [y_coordinate]
Here is documentation about adb and intent.
Hope this helps.