例子:
(
目的是使bat脚本关闭后,startFloatWindow.sh继续运行。
这里使用a.sh脚本过渡,来后台启动startFloatWindow.sh。
关键点有两个:
1、a.sh中的&,表示后台启动新进程;
2、bat脚本中执行a.sh时,使用adb shell < temp.txt的方式,否则a.sh无法调用到startFloatWindow.sh
)
1、bat脚本内容如下:
adb push startFloatWindow.sh /data
adb push a.sh /data
adb shell "chmod 777 /data/startFloatWindow.sh"
adb shell "chmod 777 /data/a.sh"
echo cd /data >temp.txt
echo sh ./a.sh>>temp.txt
adb shell<temp.txt
2、a.sh脚本内容如下:
#!/system/bin/sh
echo "start run monitor 1..."
sh /data/startFloatWindow.sh&
3、startFloatWindow.sh脚本内容如下:
while true;
do
am startservice com.example.a/com.huawei.zhenshimoxing.FloatWindowService
sleep 1
echo "#"
done