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();
}
标签:mReceiver,MEDIA,filter,onDestroy,Intent,ACTION,Android,监听,SD 来源: https://blog.51cto.com/u_15298588/3034429