通过命令行执行adb shell am broadcast发送广播通知。
adb shell am broadcast 后面的参数有:
[-a
[-c
[-e|--es
[--esn
[--ez
[--ei
[--el
[--ef
[--eu
[--ecn
[--eia
(mutiple extras passed as Integer[])
[--eial
(mutiple extras passed as List
[--ela
(mutiple extras passed as Long[])
[--elal
(mutiple extras passed as List
[--efa
(mutiple extras passed as Float[])
[--efal
(mutiple extras passed as List
[--esa
(mutiple extras passed as String[]; to embed a comma into a string,
escape it using "\,")
[--esal
(mutiple extras passed as List
escape it using "\,")
[--f
[--grant-read-uri-permission] [--grant-write-uri-permission]
[--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
[--debug-log-resolution] [--exclude-stopped-packages]
[--include-stopped-packages]
[--activity-brought-to-front] [--activity-clear-top]
[--activity-clear-when-task-reset] [--activity-exclude-from-recents]
[--activity-launched-from-history] [--activity-multiple-task]
[--activity-no-animation] [--activity-no-history]
[--activity-no-user-action] [--activity-previous-is-top]
[--activity-reorder-to-front] [--activity-reset-task-if-needed]
[--activity-single-top] [--activity-clear-task]
[--activity-task-on-home]
[--receiver-registered-only] [--receiver-replace-pending]
[--receiver-foreground]
[--selector]
[
例1:
adb shell am broadcast -a com.android.test --es test_string "this is test string" --ei test_int 100 --ez test_boolean true
说明:--es 表示使用字符串类型参数 --ei 表示int类型参数 --ez 表示boolean类型参数 蓝色为key,红色为alue
例2:蓝色为key,红色为value,分别为String类型,int类型,boolean类型
adb shell am broadcast -a android.intent.action.gz.setpoweronoff --eia timeon 2019,7,8,17,55 --eia timeoff 2019,7,8,17,46 --ez enable true
说明:--eia 表示使用int[]参数 蓝色为key,红色为value
等价于以下java代码
Intent intent1 = new Intent("android.intent.action.gz.setpoweronoff");
int[] timeon = {2019,7,8,17,55};
int[] timeoff= {2019,7,8,17,46};
intent.putExtra("timeon", timeon);
intent.putExtra("timeoff", timeoff);
intent.putExtra("enable",true); //使能开关机功能, 设为false,则为关闭,true为打开
sendBroadcast(intent);