How do I get a broadcast for USB Storage Device and access it on Android?

Viewed 146

I'm making an application to browse data in a card reader and perform some operations on the data in it. But the MEDIA_MOUNTED intent in Android doesn't seem to fire up when I connect an external device.

The broadcast receiver that I set up is as follows. However, it never receives the broadcasts.

<receiver
    android:name=".MediaReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_UNMOUNTED" />
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
        <action android:name="android.intent.action.MEDIA_EJECT" />
        <data android:scheme="file"/>
    </intent-filter>
</receiver>

I have tried running this application on Samsung, MI, and OnePlus phones as of now along with an Android One phone. These devices just don't send the broadcast. I tried a Moto G phone and this was working just fine on it.

Has anyone found a workaround for this?

Note: I tried logging the broadcasts that the Operating System sends when I connect and there is no Media_Mounted, Media_Unmounted, or related Broadcast among them. I only get USB_DEVICE_ATTACHED and USB_DEVICE_DETACHED broadcasts.

0 Answers
Related