android 开机启动一个流量提示的dialog
来源:互联网 发布:理发店女性消费数据 编辑:程序博客网 时间:2024/09/21 09:04
原理很简单,监听系统启动时候的广播:android.intent.action.BOOT_COMPLETED
监听该广播时需要添加权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
广播注册,一定要加category否则无法监测到:
<receiver
android:name=".DataConnectTipReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>
然后是设置dialog,其他东西就不详细展示,展示核心代码:
alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alertDialog.show();
注意:使用的是Alertdialog,先调用create()方法得到一个dialog对象然后设置该dialog的窗口类型为WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,如果不这么设置dialog将会因为没有上下文而报错,。
最后只要将广播安装就好了,开机的时候就能看到效果了,在此分享一个模拟开机广播的方法:
调用adb:adb shell am broadcast -a android.intent.action.BOOT_COMPLETED 模拟手机发送BOOT_COMPLETED广播
命令发送BOOT_COMPLETED广播,而不用重启测试机或模拟器来测试BOOT_COMPLETED广播,这条命令可以更精确的发送到某个package:
adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n package_name/class_name 。本次分享不多,只希望用到的时候能帮助到各位读者
————一个成长中的迷途小码农;
- android 开机启动一个流量提示的dialog
- Android--一个好玩的应用程序/开机自启动
- 创建一个开机自启动的Android系统服务
- win8系统,开机启动提示一个文件失败
- Android 如何使一个service 开机启动
- Android 让一个Service开机自动启动
- Android 之开机启动一个服务
- android 开机自启动一个activity
- android 开机自启动一个service
- Android让一个service开机自动启动
- Android 开机启动的service
- 一个android的dialog框架
- 关于Android的查询CPU、流量、内存以及获取一个app的启动activity
- Android获得本应用本次开机后的流量
- L版本开机提示“Android正在升级或启动”
- L版本开机提示“Android正在升级或启动”
- 删除Android刷机启动开机向导(气泡提示)
- android dialog提示框
- java实现ftp上传下载(jdk1.7以上)
- 【代码笔记】iOS-显示图片的各种方式
- SQL语句中有关单引号、双引号和加号的问题
- ListView源代码分析
- 如何让你的传输更安全——NIO模式和BIO模式实现SSL协议通信
- android 开机启动一个流量提示的dialog
- 又学一招——集合根据对象中摸个字段去重
- java模拟浏览器下载图片
- Java 实现当当网泄露数据快速检索
- 深入浅出Docker(一):Docker核心技术预览
- history.back();history.go(-1);触发操作后无效解决方案
- 生产实习(Android)四
- [从头学数学] 第12节 20以内的退位减法
- sql 字段属性带有双引号