android_47_BroadcastReceiver_SD卡状态监测
来源:互联网 发布:google云端硬盘知乎 编辑:程序博客网 时间:2024/05/16 11:46
效果:
清单:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sg31.mediastatusreceiver" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> //注册广播接收者 <receiver android:name=".MediaStatusReceiver"> <intent-filter > <action android:name="android.intent.action.MEDIA_MOUNTED"/> <action android:name="android.intent.action.MEDIA_REMOVED"/> <action android:name="android.intent.action.MEDIA_UNMOUNTED"/> <data android:scheme="file"/> </intent-filter> </receiver> </application></manifest>
布局:
广播接收者:
package com.sg31.mediastatusreceiver;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.widget.Toast;public class MediaStatusReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {//判断收到的到底是什么广播 String action = intent.getAction(); if("android.intent.action.MEDIA_MOUNTED".equals(action)){ Toast.makeText(context, "SD卡可用", 0).show(); } else if("android.intent.action.MEDIA_REMOVED".equals(action)){ Toast.makeText(context, "SD卡拔出", 0).show(); } else if("android.intent.action.MEDIA_UNMOUNTED".equals(action)){ Toast.makeText(context, "SD卡不可用", 0).show(); }}}
控制器:
0 0
- android_47_BroadcastReceiver_SD卡状态监测
- 监测SDcard卡状态
- Linux状态监测
- Linux 监测IO状态
- java性能,状态监测
- iphone网络状态监测
- Linuxiostat监测IO状态
- Linux 监测IO状态
- inux 监测IO状态
- 网络状态的监测
- 服务器状态监测 Keepalived
- nginx配置状态监测
- 了解综合状态监测
- iOS - 监测网络状态
- 网络状态的监测
- 监测网络状态
- 监测串口通讯状态
- NSURLCache、网络监测状态
- Android 应用程序执行Shell命令
- window.onload 、$(function())、;(function(){}()); 的执行顺序
- 编译错误"/usr/bin/ld: cannot find -lz"
- [python学习]利用generator实现杨辉三角
- iOS UIView动画
- android_47_BroadcastReceiver_SD卡状态监测
- Android L限制Ripple水波纹范围大小
- 制作tomcat docker镜像
- 【Lua】【APP】【动态】【动态APP】
- 制作文字阴影
- Java定时器、线程池练习题
- VS打包应用程序的工具及其使用方法
- 关于安装版JDK1.8 1.7更改多个JDK环境变量 不生效
- 十进制转十六进制的C语言实现