<application androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" > <receiver androID:name=".WifiReceiver" > <intent-filter> <action androID:name="androID.net.wifi.WifiManager.WIFI_STATE_CHANGED_ACTION" /> <action androID:name="androID.intent.action.PHONE_STATE" /> </intent-filter> </receiver> //activity declaration here...</application>
你们知道如何在清单中注册BraodcastReceiver?
我不想在活动中注册,因为当WiFi状态发生变化时,我想监控wifi,无论我的应用程序是否正在运行.
这是我的broadcastReceiver类:
public class WifiReceiver extends broadcastReceiver { private final String TAG = "WifiReceiver"; @OverrIDe public voID onReceive(Context context,Intent intent) { int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,WifiManager.WIFI_STATE_UNKNowN); String wifiStateText = "No State"; switch (wifiState) { case WifiManager.WIFI_STATE_disABliNG: wifiStateText = "WIFI_STATE_disABliNG"; break; case WifiManager.WIFI_STATE_Disabled: wifiStateText = "WIFI_STATE_Disabled"; break; case WifiManager.WIFI_STATE_ENABliNG: wifiStateText = "WIFI_STATE_ENABliNG"; break; case WifiManager.WIFI_STATE_ENABLED: wifiStateText = "WIFI_STATE_ENABLED"; break; case WifiManager.WIFI_STATE_UNKNowN: wifiStateText = "WIFI_STATE_UNKNowN"; break; default: break; } MyLog.d(TAG,"onReceive broadcast > WiFiState: " + wifiStateText); MyLog.d(TAG,"onReceive broadcast > Time: " + new Date()); }}
我真的希望得到一些帮助.提前致谢.
解决方法 清单中的接收者应该看起来像这样<receiver androID:name=".WifiReceiver" > <intent-filter> <action androID:name="androID.net.wifi.WIFI_STATE_CHANGED" /> </intent-filter></receiver>
还可能需要以下许可
<uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" />总结
以上是内存溢出为你收集整理的在清单中声明的android – BroadcastReceiver不接收广播全部内容,希望文章能够帮你解决在清单中声明的android – BroadcastReceiver不接收广播所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)