Reputation: 321
I need to implement the sd card removal notification which is already present in android, I need to know how it is being done?? Any sample code or tutorial would be of much help.
Upvotes: 4
Views: 2527
Reputation: 7087
you need to use Broadcast Receiver for SD Card Removed
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//If SD Card is Removed it will Come Here
//Intent service = new Intent(context, WordService.class);
//context.startService(service);
}
}
Add Receiver in your Android Manifest File Like Below Code.
<receiver android:name="MyReceiver " >
<intent-filter>
<action android:name="android.intent.action.MEDIA_EJECT" />
</intent-filter>
</receiver>
Upvotes: 5
Reputation: 16914
The system broadcasts Intents on various events, many of which are about the state changes of the SD card (external media).
So you just need to set up a BroadcastReceiver for the proper Intents. Check out this page for reference. You're looking for the ACTION_MEDIA_* Actions.
Upvotes: 1