如何根据来自不同活动的首选项复选框在启动时发送状态栏通知?

时间:2011-05-22 19:05:17

标签: java android xml broadcastreceiver

我之前可能会问过类似的question,但是当手机启动时我的广播接收器仍然存在问题。所以我需要知道的是如何做一个基本的广播接收器,根据来自不同活动天气的复选框偏好发送状态栏通知,它是否被检查?我想如何在清单文件中列出它?

1 个答案:

答案 0 :(得分:0)

如果BroadcastReceiver和Activity在同一个包中,那么您可以:

  1. 创建BOOT_COMPLETED BroadcastReceiver(请参阅http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/
  2. 在接收器中读取首选项:我通常在接收器中使用SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);来获取全局首选项对象。
  3. 使用getSystemService获取NotificationManager(请参阅http://developer.android.com/reference/android/content/Context.html#getSystemService%28java.lang.String%29http://developer.android.com/reference/android/app/NotificationManager.html)。
  4. 使用NotificationManager显示通知。