【问题标题】:Broadcast Receivers广播接收器
【发布时间】:2015-09-18 04:34:16
【问题描述】:

我需要编写一个 android 应用程序来检测以下广播接收器并将它们显示在一个对话框中,当用户单击该框时它会消失。 1. 电源连接 2. 电源断开 3. 电池电量低 4.电池没问题 5.振铃模式改变 6. WiFi状态改变

怎么做?

【问题讨论】:

    标签: android


    【解决方案1】:

    您的每个应用行为都需要内部相关的系统操作名称。但是,你可以把它们放到一个receiver中进行xml注册,并使你的receiver类成为一个功能监视器,例如:

    <receiver android:name=".myReceiver"> <intent-filter> <action android:name="android.intent.action.ACTION_POWER_CONNECTED"/> <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/> <action android:name="android.intent.action.ACTION_BATTERY_LOW"/> <action android:name="android.intent.action.ACTION_BATTERY_OKAY"/> <action android:name="android.media.RINGER_MODE_CHANGED"/> <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/> </intent-filter> </receiver>

    【讨论】:

      【解决方案2】:

      当某些硬件事件发生时,系统范围内的意图是让应用程序得到通知。例如,对于电池检查 http://developer.android.com/training/monitoring-device-state/battery-monitoring.html http://stackoverflow.com/questions/13228849/how-to-detect-when-the-batterys-low-android

      对于其他事件,搜索 Intent 并在 android manifest 中注册它们并注册一个接收器。应该很简单。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多