How to check if sendBroadcast has completed its work

I have few problems. I am updating my SD card using:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 

and I created a ProgressDialog with a counter that appears at the beginning ("at the beginning" - I mean after the sendBroadcast method), and after a successful update I would like to reject it, but I had no idea how to verify that MediaScanner finished work. I tried using BroadcastReciver and sendStickyOrderedBroadcast(...) , but it seemed like the wrong idea ...

I cannot use MediaScannerConnection and OnScanCompletedListener() , because I do not have direct paths to files (in some situations it does not exist). Does anyone know how to solve my problem? I'm out of ideas

+4
source share
1 answer

When you send a broadcast, you cannot expect a result. The only way you will ever get them is with the receiver (in this case, MediaScannerService, which catches the ACTION_MEDIA_MOUNTED transmission) sends its own broadcast with the update of the “job”.

You can catch ACTION_MEDIA_SCANNER_FINISHED for your current circumstances, however, if you want more control (like scanning specific files or scanning) you can implement MediaScannerConnectionClient .

+1
source

Source: https://habr.com/ru/post/1402543/


All Articles