• [方法提炼] 获取Android设备序列号方法


    通过这个方法可以检测设备是否连接成功,如果有一台或者多台设备,可以将所有设备序列号全部输出

     1 # -*- coding:utf-8 -*-
     2 import os
     3 
     4 def attachDeviceList():
     5     device_list = []
     6     cmd_output = os.popen("adb devices","r").read().split()[4:]   # 从输出的列表中第5个开始为设备序列号,将后面所有内容全部输出
     7     for i in range(len(cmd_output)):
     8         if i%2 == 0:    # 列表位置为偶数的全部为设备序列号,将device字符除去
     9     #         print (cmd_output[i])
    10             device_list.append(cmd_output[i])  # 将提取出来的序列号加入到device_list列表中
    11 #     print (device_list)
    12     if device_list:    # 通过判断列表是否为真(有数据),说明获取设备序列号成功
    13         return device_list
    14     else:
    15         return "No device found.
    Please check whether the device is connect or not!"
    16 
    17 if __name__ == "__main__":
    18     print (attachDeviceList())

    无设备连接输出如下:

    No device found.
    Please check whether the device is connect or not!
    

      

    有一台设备连接如下:

    ['75AQP7JVAQBAHMV4']
    

      

    有两台设备连接如下:

    ['75AQP7JVAQBAHMV4', 'RWGESGIFYL8H55M7']
    

      

    有三台设备连接如下:

    暂时没有这么多设备,请自行拿代码去验证 ^_^

  • 相关阅读:
    UVa 839 -- Not so Mobile(树的递归输入)
    UVa 548 -- Tree
    UVA 122 -- Trees on the level (二叉树 BFS)
    UVa679 小球下落(树)
    POJ 2255 -- Tree Recovery
    POJ 1451 -- T9
    POJ 2513 -- Colored Sticks
    STL -- heap结构及算法
    nginx利用try_files实现多个源
    nginx location的优先级
  • 原文地址:https://www.cnblogs.com/aziji/p/9909076.html
Copyright © 2020-2023  润新知