Android中常用adb的命令

介绍一点安卓开发中常用的adb命令。

1.安卓开发中常用的adb命令

  • 打印手机显示的当前页面
//首先进入shell命令行模式
adb shell
//显示当前Activity信息
logcat -s ActivityManager
  • 安装APP
adb install -r AndroidTest.apk

这里添加 -r 参数可以在不卸载旧版的情况下,进行版本升级。
- 卸载APP

adb uninstall com.example.androidtest
  • 启动Activity
adb shell am start com.example.androidtest/.MainActivity
or
adb shell am start com.example.androidtest/com.example.androidtest.MainActivity

这里有一个要求:要启动的Activity在Manifest中有:

<intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        android:exported="true"
  • 使用默认浏览器打开一个URL
adb shell am start -a android.intent.action.VIEW -d http://www.baidu.com
  • 关闭/打开手机屏幕
adb shell input keyevent 26
  • 清除APP数据
adb shell pm clear com.example.androidtest
  • 打印日志信息
adb logcat

执行上面的命令会打印N多的信息,下面对信息进行一下筛选

  • 通过tag过滤
    输出指定tag(xxx或 (xxx和yyy))的内容
adb logcat -s xxx
or
adb logcat -s xxx yyy
  • 通过优先级过滤
    打印warn及其以上的日志信息:
adb logcat *:W

安卓中日志信息中优先级情况:
V - Verbose (lowest priority)
D - Debug
I - Info
W - Warning
E - Error
F - Fatal
S - Silent (highest priority, on which nothing is ever printed)

  • 通过tag&&优先级进行过滤
adb logcat -s xxx:W
or
adb logcat -s xxx:W yyy:W    
  • 清空日志
adb logcat -c

翻译地址:
http://www.growingwiththeweb.com/2014/01/handy-adb-commands-for-android.html

  • 录制视频
adb shell screenrecord /sdcard/movie.mp4

可以按Ctrl+C停止。

第三方软件占用adb端口问题

这种情况,经常发生在电脑空闲时间较长的时候。
1.在Windows的Path中配置上adb的路径(PS:这样就不用每一次调用adb命令,都必须转到adb.exe文件所在的目录了)
1.下午如果手机出现连接不上电脑的情况,win+R,打开控制台,输入
adb kill-server
adb start-server adb 可能就连接上了(不过一般都是老样子,adb restart-server 这个命令不是很好使),如果出现下图的情况,基本上就是越俎代庖了。
这里写图片描述
2.此时很有可能,是第三方软件,占用了adb需要使用的端口。使用
adb nodaemon server
在确认一下。
这里写图片描述
3.执行一下命令,看一下那个贱人是谁(只能看到其PID)

netstat -ano | findstr “5037”

这里写图片描述
4.到任务管理器
这里写图片描述
这里写图片描述
5.结束掉该进程,然后再命令行执行:
adb start-server
这时一般就好了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值