Reputation: 1005
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
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
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
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