How to call getPackageManager() from Android command-line executable

眉间皱痕 提交于 2020-01-16 11:16:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!