当sd卡被播出的时候,系统是会发出广播的。
你可以接受这广播做相应的处理。
 
这点是绝对可能的。因为已经实现过了,
关键代码:
       intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
        intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
        intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED);
        intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
然后注册接收器,接收广播就可以了。
       

解决方案 »

  1.   

        下面是我的主要代码?还有那些需要注意的吗?    
    MyBroadcastReceiver mReceiver = new MyBroadcastReceiver();
    IntentFilter intentFilter =new IntentFilter();
            intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
            intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
            intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
            intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);      
            registerReceiver(mReceiver, intentFilter);
    private class MyBroadcastReceiver extends BroadcastReceiver {     
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                 Log.i("", "hava no sdacrd");
                } else if (action.equals(Intent.ACTION_MEDIA_BAD_REMOVAL)) {
                 Log.i("", "hava no sdacrd1");
                } else if (action.equals(Intent.ACTION_MEDIA_UNMOUNTED)) {
                 Log.i("", "hava no sdacrd2");             } else if (action.equals(Intent.ACTION_MEDIA_REMOVED)) {
                 Log.i("liuyou", "hava no sdacrd3");
                }
            }
        }