Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get Broadcast receive when SD Card is unmounting android

I need to get the broadcast receive when media is unmounting i.e before it is being unmounted.

So that i can save the file in SD Card before Media is unmounted.

i used android.intent.action.MEDIA_UNMOUNTED.

        <intent-filter>
            <action android:name="android.intent.action.MEDIA_UNMOUNTED" />
            <data android:scheme="file" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>

But it received after the media was unmounted and then I was not able to save the file.

I also tried MEDIA_EJECT, MEDIA_SHARED, all this are received after Media is Unmounted.

Is there any other way to save the file. I don't want to use Thread for saving File.

like image 588
Vivek Khandelwal Avatar asked Feb 04 '12 08:02

Vivek Khandelwal


2 Answers

Use ACTION_MEDIA_EJECT: User has expressed the desire to remove the external storage media. Applications should close all files they have open within the mount point when they receive this intent. The path to the mount point for the media to be ejected is contained in the Intent.mData field.

like image 110
Maz Avatar answered Nov 12 '22 18:11

Maz


try android.intent.action.ACTION_MEDIA_UNMOUNTED it should receive broadcast. but i am not sure. never used.

like image 30
Seshu Vinay Avatar answered Nov 12 '22 17:11

Seshu Vinay