Android access: installLocation manifest attribute

I am trying to write an Android 2.2 application that will find installed applications that can be transferred to an SD card. The permission to do this is encoded in the AndroidManifest.xml file as an attribute of the Android root level : INSTALLLOCATION . " PackageInfo seems to have an interface to everything except this attribute. I can open the installed apk and extract the AndroidManifest.xml file, but it seems to be in some binary coding format that some random internet users wrote a decoder, but it seems like a terrible job.

Is there an interface that I am missing?

+6
android xml android-manifest
source share
4 answers

As it turned out, while there is no direct API call to get installLocation , I also do not have to parse the binary XML manually, since XmlResourceParser works on it.

 // 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(); } 

I think there is a switch with one case , which should just be if . Well. You understand.

+12
source share

Given all the other direct attributes of the manifest tag are available from PackageInfo, I think you're right to look for it there.

I know this is not in the dock, but have you tried it anyway? Something like

 PackageInfo pkg = ...; String loc = pkg.installLocation(); 

I know that this is probably very naive, given that the document can be generated automatically - and I would not dare to offer it if I could try it myself (stuck on API 7 at the moment because of a backward OS that is larger not supported in 8)

If this does not work, I’m afraid that they simply did not pay attention to it - I can’t imagine that they will suddenly express it elsewhere. In this case, you are probably stuck in parsing manifestations.

0
source share

Since 2007, in the PackageInfo class, public fields have been opened in the older API, which provided all the information about internal localization and other relevant information. For security reasons, I assume that they got rid of these convenient fields.

0
source share

You can access this attribute in the following example:

 PackageInfo packageInfo = context.getPackageManager().getPackageInfo(mPackageName, 0); if (packageInfo.installLocation != PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) { ..... } 

http://developer.android.com/reference/android/content/pm/PackageInfo.html#installLocation
was introduced in API 21

But this field even exists in Android 2.3 http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/android/content/pm/PackageInfo.java/

0
source share

All Articles