<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.emnets.luoly.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="19" />
<uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name= "android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name="com.emnets.luoly.sample.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我想使用groovy获取uses-permission
。
也许是这样,
def manifestXml = new XmlParser().parse(Manifest)
manifestXml."uses-permission".each { p ->
println p.attribute("android:name")
}
如何获取android.permission.WRITE_EXTERNAL_STORAGE
答案 0 :(得分:3)
您可以使用XmlSlurper
def manifestXml = new XmlSlurper().parse(Manifest)
manifestXml."uses-permission".each { p ->
println p."@android:name"
}
答案 1 :(得分:0)
使用XmlSlurper获取ActivityName
def manifest = new XmlSlurper().parse(xmlFilePath)
String pkg = manifest.@package
manifest.application.activity.each {
String actName = it.'@android:name'
if (actName.substring(0, 1).equals('.')) {
actName = pkg + actName
}
println(actName)
}