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();
}