事實證明,雖然沒有直接的API調用來獲得installLocation
,但我也不得不手動解析二進制XML,因爲所提供的XmlResourceParser
對其起作用。
// Experimentally determined
private static final int auto = 0;
private static final int internalOnly = 1;
private static final int preferExternal = 2;
AssetManager am = createPackageContext(packageName, 0).getAssets();
XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
xmlloop:
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
if (! xml.getName().matches("manifest")) {
break xmlloop;
} else {
attrloop:
for (int j = 0; j < xml.getAttributeCount(); j++) {
if (xml.getAttributeName(j).matches("installLocation")) {
switch (Integer.parseInt(xml.getAttributeValue(j))) {
case auto:
// Do stuff
break;
case internalOnly:
// Do stuff
break;
case preferExternal:
// Do stuff
break;
default:
// Shouldn't happen
// Do stuff
break;
}
break attrloop;
}
}
}
break;
}
eventType = xml.nextToken();
}
嗯,我猜那裏面有一個switch
一個case
應該可能只是一個if
。好吧。你明白了。
似乎相對容易 - 很好知道! – Joubarc 2010-07-11 19:09:35