android – MEDIA_MOUNTED广播未收到

前端之家收集整理的这篇文章主要介绍了android – MEDIA_MOUNTED广播未收到前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我很困惑我正在尝试配置我的应用程序来响应SD卡变得可用/离线,但我的广播接收器永远不会被呼叫!

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

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

我的清单接收者声明:

  1. <receiver android:name=".Test" android:enabled="true">
  2. <intent-filter>
  3. <action android:name="android.intent.action.MEDIA_MOUNTED" />
  4. </intent-filter>
  5. </receiver>

我的接收器有一个onReceive方法

  1. public class Test extends BroadcastReceiver {
  2.  
  3. @Override
  4. public void onReceive(Context context,Intent intent) {
  5. Log.d("#########","##############################################################");
  6. Log.d("#########","Obligitory snarky and/or funny logging comment...");
  7. Log.d("#########","##############################################################");
  8. }
  9. }

然而& ^%$的事情不会导致Test.onReceive()触发.有什么想法吗?

解决方法

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

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

  1. <receiver android:name=".Test" android:enabled="true">
  2. <intent-filter>
  3. <action android:name="android.intent.action.MEDIA_MOUNTED" />
  4. <data android:scheme="file"/>
  5. </intent-filter>
  6. </receiver>

猜你在找的Android相关文章