2012-01-09 59 views

回答

3

以下是我如何检查存储卡是否安装/卸下。你可以改变它来检查删除/ insterted。我这样做是通过注册一个BroadcastReceiver来获取“mount事件”,然后检查存储卡处于何种状态。如果没有安装它,并且不是在检查时(重新安装卡时的状态),它将被卸载或该卡已被移除。

public class MemCardReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ 
      onMemcardMounted(); 
     } 
     else if (!Environment.getExternalStorageState().equals(Environment.MEDIA_CHECKING)){ 
      onMemorycardUnMounted(); 
     } 
    } 

    private void onMemorycardUnMounted() {} 

    private void onMemcardMounted() {} 
} 

而且在manifest资源配置文件

<receiver android:enabled="true" android:exported="true" android:name="the.name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MEDIA_MOUNTED" /> 
      <action android:name="android.intent.action.MEDIA_UNMOUNTED" /> 
      <data android:scheme="file" /> 
     </intent-filter> 
    </receiver> 

有几种不同的状态checkout this如果有任何其他规定等。删除

0

我认为android.Intent.action.ACTION_MEDIA_EJECT广播当用户使用USB存储和ACTION_MEDIA_MOUNTED关闭时。

相关问题