MEDIA_MOUNTED broadcast not being received

I’m baffled. I’m trying to configure my app to respond to the SD card becoming available / going offline, but my broadcast receiver never gets called!

I can see the event being broadcasted, and other apps responding:

  • Android, Gradle. How to build application and run tests from test application
  • Error:Cause: unable to find valid certification path to requested target
  • How to get raw preview data from Camera object at least 15 frames per second in Android?
  • How to update E-mail, Address, Nickname, etc of a contact in Android?
  • Write an application that can use plugins
  • How do I disable orientation change on Android?
  • 08-21 23:43:04.405: DEBUG/Ringer(275): -- intent.getAction() =android.intent.action.MEDIA_MOUNTED
    

    And my manifest has the receiver declared:

        <receiver android:name=".Test" android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.MEDIA_MOUNTED" />
            </intent-filter>
        </receiver>
    

    And my receiver has an onReceive method:

    public class Test extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("#########", "##############################################################");
            Log.d("#########", "Obligitory snarky and/or funny logging comment...");
            Log.d("#########", "##############################################################");
        }
    }
    

    Yet the &^%$’ing thing won’t cause Test.onReceive() to fire. Any thoughts?

    Related posts:

    Enforcing spaces in string resources
    Using Observable in Android
    crash with NoSuchMethodError after proguard with method references
    Setting ID for Spinner items
    Android - Problems with logging the start up latency
    How to get the number of unread gmail mails (on android)
  • SharedPreferences application context vs activity context
  • How to run apk file on Mac via Bluestacks
  • Slide In button effect of List View item for Android
  • AudioFlinger could not create record track, status: -1 , Need help to ifx
  • Listitem click doesn't work with checkboxes Android
  • How to customize the back button on ActionBar
  • 2 Solutions collect form web for “MEDIA_MOUNTED broadcast not being received”

    You can’t be serious. Apparently I needed to add an additional filter for the data type.

    Leaving the answer up for “the next guy”…

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

    You try adding the <data android:scheme="file" /> tag in the <intentfilter>, else do the registration at run time.
    At run time, create an object of your broadcast receiver and pass it to registerReceiver(obj).

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.