0

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,

youkier
  • 13
  • 1
  • 2

1 Answers1

4

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.

royatirek
  • 2,437
  • 2
  • 20
  • 34
  • Hi, Thanks a lot for the quality of your answer, that helps a lot. adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' will help a lot, I used to look at logcat but it was not that easy... Is there any command that enables to get the details of activities/intents that are used when I launch one action ? I tried with logcat but I couldn't find everything. Thanks for your help – youkier Nov 06 '18 at 07:24
  • Sorry. I don't know about any command but you can search here, otherwise ask a new question. – royatirek Nov 06 '18 at 10:52
  • Great answer, I didn't know about the android:exported, thanks for highlighting that. – Givi Mar 05 '22 at 11:42