首页 > 代码库 > android 命令行启动“未知”APK

android 命令行启动“未知”APK

场景:

手机上或者开发版上没有一个可用的launcher 用于显示APK,  而我们又想启动它,该怎么办呢?


办法

这时候就需要从命令行启动,而从命令行使用am命令启动需要知道对应APK具体的包名以及主activity名,如何得知呢?

使用aapt dump badging *.apk可以查看这个apk文件的程序名、包名、所用的sdk。举例:

aapt dump badging HelloWorld.apk
package: name='<span style="color:#ff0000;">com.example.helloworld</span>' versionCode='1' versionName='1.0'
sdkVersion:'18'
targetSdkVersion:'19'
uses-permission:'android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission:'android.permission.READ_EXTERNAL_STORAGE'
application-label:'HelloWorld'
application-icon-160:'res/drawable-mdpi/ic_launcher.png'
application-icon-240:'res/drawable-hdpi/ic_launcher.png'
application-icon-320:'res/drawable-xhdpi/ic_launcher.png'
application-icon-480:'res/drawable-xxhdpi/ic_launcher.png'
application: label='HelloWorld' icon='res/drawable-mdpi/ic_launcher.png'
application-debuggable
launchable-activity: name='<span style="color:#ff0000;">com.example.helloworld.MainActivity</span>'  label='HelloWorld' icon=''
uses-feature:'android.hardware.touchscreen'
uses-implied-feature:'android.hardware.touchscreen','assumed you require a touch screen unless explicitly made optional'
main
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '240' '320' '480'



红色内容就是包名和主页面类名,再结合am命令就可以启动对应的程序了。

举例 adb shell am start -n com.example.helloworld/.MainActivity

具体的am指令可以参考

http://blog.csdn.net/tiantianshangcha/article/details/41445775


android 命令行启动“未知”APK