微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – MEDIA_MOUNTED广播未收到

我很困惑我正在尝试配置我的应用程序来响应SD卡变得可用/离线,但我的广播接收器永远不会被呼叫!

我可以看到正在广播的事件,其他应用程序的响应:

08-21 23:43:04.405: DEBUG/Ringer(275): -- intent.getAction() =android.intent.action.MEDIA_MOUNTED

我的清单接收者声明:

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

我的接收器有一个onReceive方法

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()触发.有什么想法吗?

解决方法

你不能认真显然,我需要为数据类型添加一个额外的过滤器.

留下“下一个人”的答案…

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

原文地址:https://www.jb51.cc/android/310931.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐