Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android intent for sdcard ready

I have an application that uses a file on the SD card, the application runs when the phone boots, and it has become apparent that the file cannot be accessed when the program is first run as it starts working before SD card is avaliable.

Is there an broadcast receiver I can use to tell when the SD card is ready?

Update

Just to summarise the answer to register the intent do:

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

and create a broadcast receiver to react to it:

private BroadcastReceiver mSDInfoReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context arg0, Intent intent) {
    // Code to react to SD mounted goes here
    }
 }; 
like image 375
stealthcopter Avatar asked Aug 05 '10 16:08

stealthcopter


1 Answers

Lookup ACTION_MEDIA_MOUNTED broadcast action on the 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"
like image 124
Pentium10 Avatar answered Nov 12 '22 04:11

Pentium10