MEDIA_MOUNTED广播没有被接收MEDIA_MOUNTED

2023-09-04 09:29:17 作者:我不坏也不是什么好人,我只是随着我的性子做一些喜欢做的事罢了

我百思不得其解。我想配置我的应用程序,以应对SD卡变得可用/脱机,但我的广播接收器不会被调用!

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>

和我的接收器具有的onReceive方法:

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("#########", "##############################################################");
    }
}

然而,和放大器; ^%$'荷兰国际集团的事情不会造成Test.onReceive()开火。有什么想法?

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

推荐答案

您不是认真的。显然,我需要添加一个额外的过滤器的数据类型。

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>
相关推荐