I am doing a media file scan using sendBroadcast. Then I need to wait till it’s complete after doing sendBroadcast. How do I do this in Android ?
I know I can use a simple while logic here but I am looking for a better approach
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
// wait here till till do something completed
Receiver
private BroadcastReceiver mediaScanner = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
// Do some thing here.
}
}
}
Here is the code to check whether media scanner is running.
I posted the answer here
http://androidbridge.blogspot.com/2012/06/how-to-check-whether-android-media.html