Use Python to write scripts to get information about the current application of the phone apk _python

Source: Internet
Author: User

If you have set the ANDROID_HOME environment variable, use the AAPT tool to get apk information and save it to the PackageInfo.txt file in the directory where the script resides:

Import OS import tempfile import re tempfile = Tempfile.gettempdir () def get_aapt (): If "Android_home" in Os.envir On:rootdir = Os.path.join (os.environ["Android_home"], "build-tools") for path, subdir, files in Os.walk (RootDir): if Aapt.exe "in Files:return os.path.join (path," Aapt.exe ") Else:return" Android_home not exist "Def Get_current_packa Ge_name (): pattern = Re.compile (r "[A-za-z0-9\.] +/. [A-za-z0-9\.] + ") os.popen (" adb wait-for-device ") out = Os.popen (" adb Shell Dumpsys Input | Findstr focusedapplication "). Read () Package_name = Pattern.findall (out) [0].split ("/") [0] return package_name def get_ MATCH_APK (package_name): list = [] for packages in Os.popen ("adb shell pm List packages-f" + package_name). ReadLines ()  : List.append (Packages.split (":") [ -1].split ("=") [0]) Apk_name = List[0].split ("/") [-1] os.popen ("adb pull" + list[0] +  "" + tempfile) return tempfile + "\" + apk_name if __name__ = = "__main__": Os.popen (get_aapt () + \ "Dump badging " + \ get_match_apk (Get_current_package_name ()) + \ "> PackageInfo.txt") os.popen ("del" + Tempfile + "\\*.apk") 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.