检测当前手机正在运行的APP

import re #一定要引入,否则不提示错误,但找不到目标
def
jiance(sjh): aakk="adb -s {0} shell dumpsys activity activities".format(sjh) aak="adb -s {0} shell am start -n com.kuaishou.nebula/com.yxcorp.gifshow.HomeActivity".format(sjh) zh=[] lx=[] ap=0 p = subprocess.Popen(aakk, shell=True, stdout=subprocess.PIPE) out, err = p.communicate() time.sleep(4) #print(out.splitlines()[24:27]) for line in out.splitlines(): aa=line.decode("utf-8") #print(len(aa)) try: ab=re.findall('cmp=com.(.*?)/',aa) #al=ab[0]+'.HomeActivity' if len(ab)>0: break except: continue try: aa=ab[0] except: ap=1 if ap==0: if aa=="kuaishou.nebula": print("已经运行") pass else: process = subprocess.Popen(aak,shell=True) time.sleep(2) print("已经重新打开了") else: print("没有得到ab")

 

aakk="adb devices"
aakk="adb shell dumpsys window w |findstr \/ |findstr name="
aakk="adb shell dumpsys activity activities"

def jiance():
    zh=[]
    lx=[]
    p = subprocess.Popen(aakk, shell=True, stdout=subprocess.PIPE)
    out, err = p.communicate()
    #print(out.splitlines()[24:27])
    for line in out.splitlines():
        aa=line.decode("utf-8")
        #print(len(aa))
        try:
            ab=re.findall('cmp=com.(.*?)/',aa)
            #al=ab[0]+'.HomeActivity'
            if len(ab)>0:
                return ab[0]
                break
        except:
            print("没有")
aa=jiance()
print(aa)  
运行快手:

adb shell am start -n com.kuaishou.nebula/com.yxcorp.gifshow.HomeActivity
adb shell am start -n com.kuaishou.nebula/com.yxcorp.gifshow.activity.UriRouterActivity

 

posted @ 2020-12-05 21:18  myrj  阅读(536)  评论(0编辑  收藏  举报