关于sd卡插拔广播

来源:互联网 发布:环境监测系统网络 编辑:程序博客网 时间:2024/05/18 13:06

文章转自:http://blog.csdn.net/wu_shu_jun/article/details/7764583


Sd卡插入和拔出的广播:

MEDIA_BAD_REMOVAL_ACTION        
广播:扩展介质(扩展卡)已经从 SD 卡插槽拔出,但是挂载点 (mount point) 还没解除 (unmount)。       
"android.intent.action.MEDIA_BAD_REMOVAL"
String
        
MEDIA_EJECT_ACTION        
广播:用户想要移除扩展介质(拔掉扩展卡)。      
"android.intent.action.MEDIA_EJECT"
String
        
MEDIA_MOUNTED_ACTION       
广播:扩展介质被插入,而且已经被挂载。        
"android.intent.action.MEDIA_MOUNTED"
String
        
MEDIA_REMOVED_ACTION        
广播:扩展介质被移除。        
"android.intent.action.MEDIA_REMOVED"
String
        
MEDIA_SCANNER_FINISHED_ACTION       
广播:已经扫描完介质的一个目录。     
"android.intent.action.MEDIA_SCANNER_FINISHED"
String

        
MEDIA_SCANNER_STARTED_ACTION
广播:开始扫描介质的一个目录。     
"android.intent.action.MEDIA_SCANNER_STARTED"
String
        
MEDIA_SHARED_ACTION      
广播:扩展介质的挂载被解除 (unmount),因为它已经作为 USB 大容量存储被共享。  
"android.intent.action.MEDIA_SHARED"
String
        
MEDIA_UNMOUNTED_ACTION        
广播:扩展介质存在,但是还没有被挂载 (mount)。        
"android.intent.action.MEDIA_UNMOUNTED" 



public class SDCardListenerextends BroadcastReceiver{


@Override

public void onReceive(Context context, Intent intent) {


String action = intent.getAction();

if (action.equals(Intent.ACTION_MEDIA_EJECT)) {

Toast.makeText(context, "TF卡被拔掉", 0).show();

}else if(action.equals(Intent.ACTION_MEDIA_MOUNTED)){

Toast.makeText(context, "TF卡被插入", 0).show();

}else if (action.equals(Intent.ACTION_MEDIA_BAD_REMOVAL)) {

Toast.makeText(context, "TF卡已经从 SD 卡插槽拔出", 0).show();

}else if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {

Toast.makeText(context, "已经扫描完介质的一个目录", 0).show();

}else if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) {

Toast.makeText(context, "开始扫描介质的一个目录", 0).show();

}else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {

Toast.makeText(context, "扩展介质存在,但是还没有被挂载 (mount)", 0).show();

}

}

      

}


在AndroidManifest.xml需要配置

<receiverandroid:name=".SDCardListener">

            <intent-filterandroid:priority="1000">

                <dataandroid:scheme="file"/>

                <actionandroid:name="android.intent.action.MEDIA_MOUNTED"/>

                <actionandroid:name="android.intent.action.MEDIA_EJECT"/>

                <actionandroid:name="android.intent.action.MEDIA_BAD_REMOVAL"/>

                <actionandroid:name="android.intent.action.MEDIA_SCANNER_FINISHED"/>

                <actionandroid:name="android.intent.action.MEDIA_SCANNER_STARTED"/>

                <actionandroid:name="android.intent.action.MEDIA_UNMOUNTED"/>

            </intent-filter>

 </receiver>









0 0
原创粉丝点击