Search code examples
androidnotificationssd-card

Android: how to know when SD-card is un-mounted


I am working on an application that reads media from the sd-card and plays it.. However, there are certain events when the sd-card is physically removed from the device or the device is attached to a computer and the sd-card is mounted on the computer.. Whenever the sd-card is removed, a notification is generated and can be seen in the notification bar. I want my application to respond to those notifications. For example, whenever the user physically removes the card or attaches it to the computer, I want my application to display a message like "sd card removed".. Is there any way to respond to these notifications??


Solution

  • I want my application to respond to those notifications.

    No, you don't. You want to respond to the broadcast Intents that are also used to create those Notifications.

    Look at the documentation for the Intent class, at the ACTION_MEDIA_* set of broadcast actions.