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

问题描述:

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

如果广播接收器和活动都在同一个包,那么您可以:

  1. 创建BOOT_COMPLETED广播接收器(见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显示通知。
+0

Thx为快速回答这看起来会帮助很多。 – camelCaseD 2011-05-22 19:22:40

+0

你如何使用'getSystemService'? – camelCaseD 2011-05-22 21:47:05

+0

这是您在'onReceive'方法中传递给上下文的方法。 – Femi 2011-05-22 21:52:14