android接收adb发送的系统广播及自定义广播
来源:互联网 发布:网络教育最快毕业几年 编辑:程序博客网 时间:2024/04/29 10:15
adb发送广播
adb shell am broadcast -a action的名字,即配置文件中action的名字
1、接收adb发送的系统的系统广播----屏幕变亮
①在程序中写一个广播接收者接收改广播
public class ScreeOnBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("shou dao le guang bo");
Toast.makeText(context, "接收到了系统屏幕变亮的广播数据", Toast.LENGTH_SHORT).show();
}
}
②在配置文件注册改广播
<receiver android:name="com.example.testbroadcast.ScreeOnBroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.ACTION_SCREEN_ON"/>
</intent-filter>
</receiver>
③在adb中输入命令
adb shell am broadcast -a android.intent.action.ACTION_SCREEN_ON
在程序中可收到发送的该广播
2、接收adb发送的系统广播------开机启动
①public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "收到了系统开机启动的广播", Toast.LENGTH_SHORT).show();
}
}
②在配置文件注册改广播
<receiver android:name="com.example.testbroadcast.BootBroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
③在adb中输入命令
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
在程序中可收到发送的该广播
注:3.0以上输入该命令,手机会重新启动后需运行程序
3、接收adb发送的自定义广播
①public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("shou dao le guang bo");
Toast.makeText(context, "接收到了自定义的广播数据", Toast.LENGTH_SHORT).show();
}
}
②在配置文件注册改广播
<receiver android:name="com.example.testbroadcast.MyBroadcastReceiver">
<intent-filter >
<action android:name="mybroadcast"/>
</intent-filter>
</receiver>
③在adb中输入命令
adb shell am broadcast -a mybroadcast
在程序中可收到发送的该广播
注:“mybroadcast”为配置文件中注册的action的名称
- android接收adb发送的系统广播及自定义广播
- Android 发送系统广播与自定义广播
- Android-自定义发送/接收广播(BroadcastReceiver)
- Android学习之发送及接收广播及本地广播
- -自定义广播的发送和接收-
- android 发送广播 接收广播 动态广播接收
- 【记录】Android 广播的发送与接收
- Android动态广播的发送和接收
- Android 广播的发送与接收
- Android广播的发送与接收
- android的广播发送与接收
- Android Activity接收Service发送的广播
- Android Activity接收Service发送的广播
- Android 广播代码的发送与接收
- Android广播的发送与接收
- android-接收系统广播
- android接收系统广播
- Android发送广播与接收广播
- 刷题-ZigZag Conversion 缺python
- setting 相关设置
- css 的注意事项
- 如何读轨道图
- 计算机网络
- android接收adb发送的系统广播及自定义广播
- vim 指令总结
- 数据链路
- HDU2004
- 让32位Eclipse跟64位Eclipse同时在64的Windows7上运行
- 尔雅通识题库系统
- Js apply call
- statfs获得硬盘使用情况
- Ant自动编译部署工具