Vivek Khandelwal
Vivek Khandelwal

Reputation: 7849

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.

Upvotes: 6

Views: 2529

Answers (3)

Maz
Maz

Reputation: 764

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.

Upvotes: 3

Cytown
Cytown

Reputation: 1547

You can only get the broadcast after it's done or doing, so you will get fail to save to sdcard.

Suggest you can save the file temporary to your internal storage then when there is a sdcard present, move it back to sdcard.

Upvotes: 0

Seshu Vinay
Seshu Vinay

Reputation: 13588

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

Upvotes: 1

Related Questions