LoginSignup
80
78

More than 5 years have passed since last update.

androidの操作を自動化したときの覚書

Last updated at Posted at 2016-03-07

androidで色々と自動化したくなったのでその覚書

端末の確認

adb devices
adb -s 端末のIDで端末を指定して実行

タップとスワイプ

タップ

adb shell input touchscreen tap x y

例によって左上が(0, 0)

スワイプ

adb shell input swipe x1 y1 x2 y2

タッチイベントを拾う

adb shell getevent /dev/input/event0

event0の部分はandroidのデバイスファイルのパス

-iオプションを付けると人が見やすい形式で出力してくれる。

ファイルの転送

PCからandroidへ

adb push PCのファイル 端末のファイル

androidからPCへ

adb pull 端末のファイル PCのファイル

androidのシェルを起動

adb shell

シェルの中ではタップなどのコマンドはadb shellを除いた部分だけで実行できる。

タッチイベントを記録&再現

record.rb
time = Time.now

while true
  if gets =~ /([a-f\d]+) ([a-f\d]+) ([a-f\d]+)/
    arr = [$1.to_i(16), $2.to_i(16), $3.to_i(16)]
    _time = Time.now
    puts "sleep #{_time - time}" if _time - time > 0.1
    puts "sendevent /dev/input/event0 #{arr[0]} #{arr[1]} #{arr[2]}"
  end
end

adb shell getevent /dev/input/event0 | ruby record.rb > touch.txtで記録。
adb push touch.txt /storage/sdcard0/で転送
adb shellでシェルに入って、sh /storage/sdcard0/touch.txtで実行

参考 getevent/sendeventでAndroid端末の操作自動化

80
78
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
80
78