I am new to Python, so this might be a way too simple question. I am trying to parse AndroidManifest.xml file to find the main activity.
XML file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.heartrateapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MonitorActivity" />
<activity android:name=".SubmitActivity" />
</application>
</manifest>
The activity with the following intent is the main activity.
<action android:name="android.intent.action.MAIN" />
Python parser:
from xml.dom.minidom import parseString
data = ''
with open('AndroidManifest.xml','r') as f:
data = f.read()
dom = parseString(data)
activities = dom.getElementsByTagName('activity')
perms = dom.getElementsByTagName('uses-permission')
for activity in activities:
print activity.getAttribute('android:name')
print activity.getElementsByTagName('intent-filter')
for perm in perms:
print perm.getAttribute('android:name')
How can I find the main activity? For now I have used print to check. I would like to create an object to store the Main Activity, intents, services, perms. etc. Could someone please help me out?