Android 监听SD卡插拨事件

BroadcastReceiver mReceiver = new BroadcastReceiver()
{
    @Override 
    public void onReceive(Context context, Intent intent)
    {
        if(intent.getAction().equals(Intent.ACTION_MEDIA_UNMOUNTED))
        {
            //...
        }
    }
};

IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
filter.addDataScheme("file");
registerReceiver(mReceiver, filter); 


@Override
protected void onDestroy()
{
    unregisterReceiver(mReceiver);//别忘了在onDestroy时销毁mReceiver
    super.onDestroy();
}

 

上一篇:Python | 实现pdf文件分页


下一篇:不下软件,照样可以完美正确格式化树莓派SD卡!(恢复U盘/SD卡到满容量)