用了好几层循环看着就难受,奈何初学者,暂时这样吧。
import os
import xml.etree.ElementTree as ET
#android namespace
namespace = '{http://schemas.android.com/apk/res/android}'
#all activity
activityArray = []
tree = ET.parse('AndroidManifest.xml')
root = tree.getroot()
packageName = root.attrib['package']
for application in root.iter('application'):
for activity in application.iter('activity'):
activityName = activity.get(namespace+'name')
#add package name
if activityName[0] == '.':
activityName = packageName+activityName
#find mainActivity
for inter in activity.iter('intent-filter'):
for action in inter.iter('action'):
if action.get(namespace+'name') =='android.intent.action.MAIN':
for cate in inter.iter('category'):
if cate.get(namespace+'name') == 'android.intent.category.LAUNCHER':
print('************\n'+activityName+'\n************')
activityArray.append(activityName)
#print(activityName)