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:

  • Get href value from anchor tag in Android WebView when link is clicked
  • how to get Theme attributes values
  • Android - Intent Filter?
  • Android slide menu that slide from both sides left and right
  • Is it possible to run R from a tablet using Honeycomb (Android 3.0)?
  • GridView row height
  • 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?

  • Android - Can't get value from EditText inside Custom Dialog
  • Gradle version 1.10 is required. Current version is 2.0
  • Detect when fragment becomes visible
  • Adding Menu to ZXings barcodescanner, and squeezing the surfaceview
  • Show fragment as a dialog or as a usual activity
  • What are the default color values for the Holo theme on Android 4.0?
  • 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.