Mr.Noob
Mr.Noob

Reputation: 1005

Android BroadCast Receiver Thread to notify sd card removal

I need help implementing a broadcast receiver that will run on a seperate thread started through an activity to notify SDCard Removal or unmounting. Can someone guide me on this please

Thank you

Upvotes: 1

Views: 1340

Answers (3)

Srikanth Roopa
Srikanth Roopa

Reputation: 1790

Create Intent Filter:

 <receiver android:name="Receiver " >
    <intent-filter>
        <action android:name="android.intent.action.ACTION_MEDIA_REMOVED" />
    </intent-filter>
</receiver>

Upvotes: 2

Rajeev
Rajeev

Reputation: 1404

You should go through this link , it tells you how to use broadcast receivers for media mount event which you can extend for your purpose (which is to listen for media unmount). And then you should register filters for all the events you want to receive, like ACTION_MEDIA_BAD_REMOVAL, ACTION_MEDIA_EJECT, ACTION_MEDIA_REMOVED and ACTION_MEDIA_UNMOUNTED.

Upvotes: 1

amalBit
amalBit

Reputation: 12181

Activity to notify SDCard Removal or unmounting

Here is the check:

Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

if(isSDPresent)
{
  // Do something
}
else
{
 // trigger the broadcast!!
}

Upvotes: 1

Related Questions