首先配置adb shell
在Android studio terminal 下运行currentActivity.sh
1、创建 touch currentActivity.sh
2、编辑 vim currentActivity.sh
3、添加运行权限 chmod 777 currentActivity.sh
4、运行 sh currentActivity.sh
5、关闭shell脚本 control + C
#!/bin/bash
#currentActivity.sh
#获取当前activitiy
old=$(adb shell dumpsys activity | grep "mFocusedActivity" | awk '{print $4}')
echo $old
while [ “1” = “1” ]
do
new=$(adb shell dumpsys activity | grep "mFocusedActivity" | awk '{print $4}')
#adb shell dumpsys activity | grep “mFocusedActivity” | cut -d ' ’ -f 6 效果同上
if [ "$new" != "$old" ];then
old=$new
echo $old
fi
done
在androidstudio里进入终端
1 cd /Users/zhanglei84/Library/Android/sdk/platform-tools
2 adb shell dumpsys activity | grep "mFocusedActivity" | awk '{print $4}'
3 退出 adb sehll :exit