Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

android - 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:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...