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:
- Create a BOOT_COMPLETED BroadcastReceiver (see http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/)
- Read the preference in the receiver: I generally use
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
in the receiver to get the global preferences object. - 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). - Show the notification using the NotificationManager.
精彩评论