我想从AndroidManifest.xml中获取versionName,versionCode和包名。 这是我到目前为止有:php从androidmanifest.xml获取manifest属性
// Load AndroidManifest.xml
$xml = simplexml_load_string($manifest);
//print_r($xml);
list(,$versionCode) = each($xml->xpath('/manifest/@android:versionCode'));
list(,$versionName) = each($xml->xpath('/manifest/@android:versionName'));
list(,$package) = each($xml->xpath('(/manifest/@package)'));
echo "versionCode: ".$versionCode.", versionName: ".$versionName.", package:".$package."\n";
我不知道是否有更好的方式来获得这些元素的值?
样品的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="1" android:versionName="1.0" package="com.example.bluetoothchat"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="11" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<application android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".BluetoothChat" android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="@string/select_device" android:name=".DeviceListActivity" android:configChanges="keyboardHidden|orientation" />
</application>
</manifest>
您是如何打开apk文件以阅读清单的? – iSun 2012-09-17 16:29:57
如何获取app_name,因为它是来自“Strings.xml”的引用文件 – twlkyao 2014-01-07 13:23:04
@iSun AndroidManifest.xml使用[AXMLPrinter2.jar](https://code.google.com/p/android4me/downloads/详细信息?name = AXMLPrinter2.jar&can = 2&q =),首先解压缩apk文件,然后进入解压目录并运行java -jar AXMLPrinter2.jar AndroidManifest.xml。 @twlkyao我没有必要获得应用程序名称,所以没有答案抱歉! – t0x13 2014-02-06 05:23:15