开发者

How to send a status bar notification on bootup based on a preference checkbox from a different activity?

I may have asked a similar question before but i'm still having issues with my 开发者_如何学编程broadcast receiver being started when the phone boots up. So what I need to know is how to do a basic broadcast receiver that sends a status bar notification based on a checkbox preference from a different activity weather it's checked or not and how i'm suppose to list it in the manifest file?


If the BroadcastReceiver and the Activity are in the same package, then you can:

  1. Create a BOOT_COMPLETED BroadcastReceiver (see http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/)
  2. Read the preference in the receiver: I generally use SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); in the receiver to get the global preferences object.
  3. Use getSystemService to get the NotificationManager (see http://developer.android.com/reference/android/content/Context.html#getSystemService%28java.lang.String%29 and http://developer.android.com/reference/android/app/NotificationManager.html).
  4. Show the notification using the NotificationManager.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜