dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.61k stars 344 forks source link

can not use the examples browser-open-url.py #303

Closed joanyy closed 2 years ago

joanyy commented 2 years ago

Hi , i used pip3 and git methods to install androidviewclient, then i can use dump , but i cannot find the fold of androidviewclient(only one on /usr/local/lib/python3.8, but it does not include examples files ), so i don't know how to write on the path of 'android_view_client_home' . when i run your example,browser-open-url.py , there is an error "ERROR: couldn't find device that matches '/home/xxxx/.local/share/jupyter/runtime/kernel-9a30b3cf-a1f5-4f11-8bbf-004e1f28b704.json' in [<com.dtmilano.android.adb.adbclient.Device object at 0x7fbc70184c40>] "

joanyy commented 2 years ago

I want to crap long mobile screenshots in bulk by androidviewclient, can i do it? i mean can i get paramenters from my apk and put params into apk? e.g., i want to put url list into the 'webview'(android studio), then automatically display each url and take a screenshot. do you have any suggestions for this?

dtmilano commented 2 years ago

Using pip3 is what you need if you are not planning to change *AndroidViewClient code.

Once installed you have dump and culebra commands available.

Also, you will be able to import AndroidViewClient modules, for example

from com.dtmilano.android.viewclient import ViewClient

That's all you need.

I don't understand what you mean by "...can i get parameters from my apk and put params into apk?". Can you give an example of that?

Also, if I understood correctly you want to open different URLs in the browser and then take the screenshot, if so this should do what you want

#! /usr/bin/env python3

import sys

from com.dtmilano.android.viewclient import ViewClient

if len(sys.argv) < 2:
    print(f'usage: {sys.argv[0]} url...', file=sys.stderr)
    sys.exit(1)

urls = sys.argv[1:]
sys.argv = [sys.argv[0]]

device, serialno = ViewClient.connectToDeviceOrExit()
cmp = 'com.android.chrome/com.google.android.apps.chrome.Main'

for n, url in enumerate(urls):
    device.startActivity(component=cmp, uri=url)
    ViewClient.sleep(5)
    device.takeSnapshot(reconnect=True).save(f'/tmp/{n}.png', 'PNG')

invoke it like

./myscript http://google.com http://github.com http://dtmilano.blogspot.com