Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart Service for App on SD Card When SD Card Is Remounted

Due to overwhelming user complaints I have decided try allowing users of my Android application to move it to the SD card as per the official documentation. However, a core feature of my application requires a background service to be continuously running. When someone who has moved my app to their SD card mounts their SD card for whatever reason, my background service will be killed.

That's all okay by me, as long as I can restart the service at the first available opportunity. Unfortunately, despite the install-location guide claiming I can use the Broadcast Intent ACTION_EXTERNAL_APPLICATIONS_AVAILABLE to detect when the SD card is remounted locally, the documentation for that flag itself, this newsgroup discussion, and my own testing show that this broadcast is not delivered to the applications which become available. Only applications which have not been moved to the SD card get the Broadcast Intent.

Is there any way to restart my background service without waiting for the user to open my app after the SD card is remounted?

like image 389
Alex Pretzlav Avatar asked Oct 18 '10 23:10

Alex Pretzlav


1 Answers

Not reliably. You could hook into permission-less broadcast Intents (e.g., ACTION_SCREEN_OFF) that should fire eventually and get control that way. As Ms. Hackborn indicates, the right answer is for ACTION_EXTERNAL_APPLICATIONS_AVAILABLE to be fixed. You might also see if some SD card-related broadcast happens to occur after external applications are available (e.g., ACTION_MEDIA_MOUNTED), though I would expect all of those to have passed before the external application is available.

like image 96
CommonsWare Avatar answered Sep 27 '22 19:09

CommonsWare