SD卡监听---BroadcastReceiver
2016-05-11 16:51
120 查看
package com.demo.sdcard; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.widget.Toast; public class SDReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //判断收到的广播类型 //获取广播中的action String action = intent.getAction(); if(Intent.ACTION_MEDIA_MOUNTED.equals(action)){ Toast.makeText(context, "sd卡就绪", 0).show(); }else if(Intent.ACTION_MEDIA_REMOVED.equals(action)){ Toast.makeText(context, "sd卡拔出", 0).show(); }else if(Intent.ACTION_MEDIA_UNMOUNTED.equals(action)){ Toast.makeText(context, "sd卡卸载", 0).show(); } } }
xml注册广播和添加sd卡状态
<pre name="code" class="java"><receiverandroid:name="com.demo.sdcard.SDReceiver"><intent-filter ><!-- 添加SD卡的状态 就绪,拔出,卸载 --><action android:name="android.intent.action.MEDIA_MOUNTED"/><action android:name="android.intent.action.MEDIA_REMOVED"/><action android:name="android.intent.action.MEDIA_UNMOUNTED"/></intent-filter></receiver>
相关文章推荐
- LeetCode 345. Reverse Vowels of a String
- VMware安装Ubuntu出现黑屏
- Xcode多种Build Configuration配置使用
- Android程序优化之监听物理回退键,退出程序
- gradle plugin user guide中文版
- oracle 修改密码,解锁
- WAMP显示错误“MSVCR100.dll”缺少安装时
- 你人生中的那口井挖了没有?
- select----2
- 去掉TableView中多余的分割线
- UE4中GameInstance和GameState区别
- 第12周阅读程序(1)(2)(3)(4)
- saltstack之(四)远程执行及常用模块
- Highcharts 相关属性
- 继承Spring AbstractRoutingDataSource实现路由切换
- 安卓_高仿QQ
- 使用补偿算法对陀螺仪和电子罗盘进行数据融合,计算方位角
- 找工作笔试面试那些事儿(13)---操作系统常考知识点总结
- 接口测试的进展
- Fiddler 教程