问题
I am writing a command-line tool for Android (such that it would be called via 'adb shell' or the like, as opposed to being launched via the Android interface).
I want to write something that uses the same kind of information as the 'pm list packages' tool that you can run from an adb shell, which I presume uses getPackageManager() or something like it.
So I've figured out how to compile and run a Java tool in Dalvik, but I can't figure out how to get it the context it needs for getPackageManager to work.
I've also tried writing a "command line" tool using Android Studio by simply not creating any views and by calling my code and then 'finish' in onCreate, but that's not quite right either, as it still briefly takes over the Android interface and it has an icon installed and so forth, which is, I'm fairly certain, not how pm works.
So - how do I write a script like 'pm' that can access installed package info, without creating an Android App?
来源:https://stackoverflow.com/questions/30764318/how-to-call-getpackagemanager-from-android-command-line-executable