am命令发送广播以及查看已发送广播信息

am命令发送广播:

am broadcast -a android.intent.action.BOOT_COMPLETED

就发送了一条开机广播,其他广播类似,其基本格式为:

am broadcast -a 你的广播


    同样,在开发过程中,有时候想知道我们自己定义的广播是否成功发送,或者是某些情况触发了系统的什么广播,那么下文告诉各位一个小技巧:

命令行执行:

dumpsys | grep BroadcastRecord

结果如下所示:

   BroadcastRecord{114315e u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{452e20c u0 android.content.jobscheduler.JOB_DELAY_EXPIRED} to user 0
    BroadcastRecord{9721755 u0 android.content.jobscheduler.JOB_DEADLINE_EXPIRED} to user 0
    BroadcastRecord{96e056a u0 AlarmTaskSchedule.com.antutu.ABenchMark} to user 0
    BroadcastRecord{37aca5b u0 com.android.server.action.NETWORK_STATS_POLL} to user 0
    BroadcastRecord{25212f8 u-1 com.android.server.action.NETWORK_STATS_UPDATED} to user -1
    BroadcastRecord{289d3d1 u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{411b137 u0 AlarmTaskSchedule.com.antutu.ABenchMark} to user 0
    BroadcastRecord{71166a4 u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{d85d7c2 u0 android.content.jobscheduler.JOB_DELAY_EXPIRED} to user 0
    BroadcastRecord{bc629d3 u0 android.content.jobscheduler.JOB_DEADLINE_EXPIRED} to user 0
    BroadcastRecord{504910 u0 com.android.providers.media.ACTIVATE_MEDIAPROCESS} to user 0
    BroadcastRecord{cddae0e u0 AlarmTaskSchedule.com.antutu.ABenchMark} to user 0
    BroadcastRecord{23f902f u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{8687fc5 u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{83f004b u0 AlarmTaskSchedule.com.antutu.ABenchMark} to user 0
    BroadcastRecord{9ec2a28 u0 android.content.jobscheduler.JOB_DELAY_EXPIRED} to user 0
    BroadcastRecord{1565341 u0 android.content.jobscheduler.JOB_DEADLINE_EXPIRED} to user 0
    BroadcastRecord{46570e6 u0 com.taobao.accs.intent.action.COMMAND} to user 0
    BroadcastRecord{4edc0d4 u0 AlarmTaskSchedule.com.antutu.ABenchMark} to user 0
    BroadcastRecord{1f3e27d u0 com.taobao.accs.intent.action.COMMAND} to user 0

从上到下,是按照从新到旧的顺序排列的,也就是说第一行是系统最新发出的一个广播。










阅读更多
个人分类: Android
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭