-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
NotificationUtils.java
53 lines (44 loc) · 3.16 KB
/
NotificationUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.android.background.utilities;
/**
* Utility class for creating hydration notifications
*/
public class NotificationUtils {
// TODO (7) Create a method called remindUserBecauseCharging which takes a Context.
// This method will create a notification for charging. It might be helpful
// to take a look at this guide to see an example of what the code in this method will look like:
// https://developer.android.com/training/notify-user/build-notification.html
// TODO (8) Get the NotificationManager using context.getSystemService
// TODO (9) Create a notification channel for Android O devices
// TODO (10) In the remindUserBecauseCharging method use NotificationCompat.Builder to create a notification
// that:
// - has a color of R.color.colorPrimary - use ContextCompat.getColor to get a compatible color
// - has ic_drink_notification as the small icon
// - uses icon returned by the largeIcon helper method as the large icon
// - sets the title to the charging_reminder_notification_title String resource
// - sets the text to the charging_reminder_notification_body String resource
// - sets the style to NotificationCompat.BigTextStyle().bigText(text)
// - sets the notification defaults to vibrate
// - uses the content intent returned by the contentIntent helper method for the contentIntent
// - automatically cancels the notification when the notification is clicked
// TODO (11) If the build version is greater than or equal to JELLY_BEAN and less than OREO,
// set the notification's priority to PRIORITY_HIGH.
// TODO (12) Trigger the notification by calling notify on the NotificationManager.
// Pass in a unique ID of your choosing for the notification and notificationBuilder.build()
// TODO (1) Create a helper method called contentIntent with a single parameter for a Context. It
// should return a PendingIntent. This method will create the pending intent which will trigger when
// the notification is pressed. This pending intent should open up the MainActivity.
// TODO (2) Create an intent that opens up the MainActivity
// TODO (3) Create a PendingIntent using getActivity that:
// - Take the context passed in as a parameter
// - Takes an unique integer ID for the pending intent (you can create a constant for
// this integer above
// - Takes the intent to open the MainActivity you just created; this is what is triggered
// when the notification is triggered
// - Has the flag FLAG_UPDATE_CURRENT, so that if the intent is created again, keep the
// intent but update the data
// TODO (4) Create a helper method called largeIcon which takes in a Context as a parameter and
// returns a Bitmap. This method is necessary to decode a bitmap needed for the notification.
// TODO (5) Get a Resources object from the context.
// TODO (6) Create and return a bitmap using BitmapFactory.decodeResource, passing in the
// resources object and R.drawable.ic_local_drink_black_24px
}