Created
September 7, 2017 21:06
-
-
Save kwong93/0ac3a56998b74acbf4c61736bc555a26 to your computer and use it in GitHub Desktop.
How to listen for sd card mount and unmount
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
Log.d("TAG", intent.getAction()); | |
} | |
}; | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
IntentFilter intentFilter = new IntentFilter(); | |
intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); | |
intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); | |
intentFilter.addDataScheme("file"); | |
registerReceiver(broadcastReceiver, intentFilter); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
unregisterReceiver(broadcastReceiver); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment