-1

On Android, there is a common solution to get the list of apps using:

PackageManager pm=getPackageManager();
List<ApplicationInfo> packages=pm.getInstalledApplications(PackageManager.GET_META_DATA)

After this query, some of the ApplicationInfo objects get their field "metadata" being filled with stuff.

My question is simple:

What is the purpose of this field?

When should we use it, and do we really need it ?

Also, what is the meaning of just using 0 as the flags? will it get all of the apps?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

1

What is the purpose of this field?

To give you the metadata for the component, as specified by <meta-data> elements in the manifest.

When should we use it

When you want to access the contents of the <meta-data> elements.

do we really need it ?

If you have <meta-data> elements, yes. Otherwise, no.

what is the meaning of just using 0 as the flags? will it get all of the apps?

It always gets "all of the apps". What the flags control is what data about those apps it retrieves. I assume this is to minimize the amount of data transferred over IPC in response to these calls, but that's just an educated guess.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • about the metadata, thanks, but it's weird that all examples use this if it's such a rare thing to use. about the flags, I'm not fully aware of all of them (i know they are mentioned on the documentations), but I think there is an irregular one called "GET_UNINSTALLED_PACKAGES" , which shows more than all apps - it shows apps that were uninstalled that have left traces of them. Is that true? if so, are there other irregular flags like this one? or are they all for getting extra data about the list of apps you get? – android developer Apr 18 '14 at 06:16
  • @androiddeveloper: Sorry, the only ones I have used just control what gets filled into the objects. Looking over the list, `GET_UNINSTALLED_PACKAGES` is the only one that would seem to control what elements are in the returned `List`. Everything else appears, at first glance, to fit my original description. I apologize for my memory lapse. – CommonsWare Apr 18 '14 at 10:57
  • ok, then. Thank you. If you are curious about why I ask this, here's my app: https://play.google.com/store/apps/details?id=com.lb.app_manager . anyway, I've now accepted your answer. – android developer Apr 18 '14 at 11:02