代码之家  ›  专栏  ›  技术社区  ›  stealthcopter

安卓SD卡准备就绪

  •  18
  • stealthcopter  · 技术社区  · 14 年前

    我有一个应用程序使用SD卡上的文件,该应用程序在手机启动时运行,而且很明显,当程序首次运行时无法访问该文件,因为它在SD卡可用之前就开始工作了。

    有没有一个广播接收器,我可以用它来判断SD卡什么时候准备好了?

    更新

    只是总结一下注册意图的答案:

    IntentFilter filter = new IntentFilter (Intent.ACTION_MEDIA_MOUNTED); 
    filter.addDataScheme("file"); 
    registerReceiver(this.mSDInfoReceiver, new IntentFilter(filter));
    

    并创建一个广播接收器对其作出反应:

    private BroadcastReceiver mSDInfoReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent intent) {
        // Code to react to SD mounted goes here
        }
     }; 
    
    1 回复  |  直到 13 年前
        1
  •  18
  •   Pentium10    14 年前

    查找 ACTION_MEDIA_MOUNTED 上的广播操作 Intent

    public static final String ACTION_MEDIA_MOUNTED
    
    Since: API Level 1
    Broadcast Action: External media is present and mounted at its mount point. The path to the mount point for the removed media is contained in the Intent.mData field. The Intent contains an extra with name "read-only" and Boolean value to indicate if the media was mounted read only.
    Constant Value: "android.intent.action.MEDIA_MOUNTED"