2010-08-05 37 views
18

我有一個使用SD卡上的文件的應用程序,應用程序在手機啓動時運行,並且很明顯,該程序在開始工作時首次運行時無法訪問該文件在SD卡可用之前。android intent for sdcard ready

是否有一個廣播接收器可以用來判斷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 
    } 
}; 

回答

18

查找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"