@@ -119,6 +119,7 @@ private void keepAwake() {
119
119
*/
120
120
private void sleepWell () {
121
121
stopForeground (true );
122
+ getNotificationManager ().cancel (NOTIFICATION_ID );
122
123
123
124
if (wakeLock != null ) {
124
125
wakeLock .release ();
@@ -129,10 +130,6 @@ private void sleepWell() {
129
130
/**
130
131
* Create a notification as the visible part to be able to put the service
131
132
* in a foreground state by using the default settings.
132
- *
133
- * @return
134
- * A local ongoing notification which pending intent is bound to the
135
- * main activity.
136
133
*/
137
134
private Notification makeNotification () {
138
135
return makeNotification (BackgroundMode .getSettings ());
@@ -142,26 +139,29 @@ private Notification makeNotification() {
142
139
* Create a notification as the visible part to be able to put the service
143
140
* in a foreground state.
144
141
*
145
- * @param settings
146
- * The config settings
147
- *
148
- * @return
149
- * A local ongoing notification which pending intent is bound to the
150
- * main activity.
142
+ * @param settings The config settings
151
143
*/
152
144
private Notification makeNotification (JSONObject settings ) {
145
+ String text = settings .optString ("text" , "" );
146
+ boolean bigText = settings .optBoolean ("bigText" , false );
147
+
153
148
Context context = getApplicationContext ();
154
149
String pkgName = context .getPackageName ();
155
150
Intent intent = context .getPackageManager ()
156
151
.getLaunchIntentForPackage (pkgName );
157
152
158
153
Notification .Builder notification = new Notification .Builder (context )
159
154
.setContentTitle (settings .optString ("title" , "" ))
160
- .setContentText (settings . optString ( " text" , "" ) )
155
+ .setContentText (text )
161
156
.setTicker (settings .optString ("ticker" , "" ))
162
157
.setOngoing (true )
163
158
.setSmallIcon (getIconResId ());
164
159
160
+ if (bigText || text .contains ("\n " )) {
161
+ notification .setStyle (
162
+ new Notification .BigTextStyle ().bigText (text ));
163
+ }
164
+
165
165
setColor (notification , settings );
166
166
167
167
if (intent != null && settings .optBoolean ("resume" )) {
@@ -178,8 +178,7 @@ private Notification makeNotification(JSONObject settings) {
178
178
/**
179
179
* Update the notification.
180
180
*
181
- * @param settings
182
- * The config settings
181
+ * @param settings The config settings
183
182
*/
184
183
protected void updateNotification (JSONObject settings ) {
185
184
boolean isSilent = settings .optBoolean ("silent" , false );
@@ -189,18 +188,14 @@ protected void updateNotification (JSONObject settings) {
189
188
return ;
190
189
}
191
190
192
- Notification notification = makeNotification (settings );
193
- NotificationManager service = (NotificationManager )
194
- getSystemService (Context .NOTIFICATION_SERVICE );
191
+ Notification notification = makeNotification (settings );
195
192
196
- service .notify (NOTIFICATION_ID , notification );
193
+ getNotificationManager ().notify (
194
+ NOTIFICATION_ID , notification );
197
195
}
198
196
199
197
/**
200
198
* Retrieves the resource ID of the app icon.
201
- *
202
- * @return
203
- * The resource ID of the app icon
204
199
*/
205
200
private int getIconResId () {
206
201
JSONObject settings = BackgroundMode .getSettings ();
@@ -222,14 +217,10 @@ private int getIconResId() {
222
217
/**
223
218
* Retrieve resource id of the specified icon.
224
219
*
225
- * @param res
226
- * The app resource bundle.
227
- * @param icon
228
- * The name of the icon.
229
- * @param type
230
- * The resource type where to look for.
231
- * @param pkgName
232
- * The name of the package.
220
+ * @param res The app resource bundle.
221
+ * @param icon The name of the icon.
222
+ * @param type The resource type where to look for.
223
+ * @param pkgName The name of the package.
233
224
*
234
225
* @return The resource id or 0 if not found.
235
226
*/
@@ -248,10 +239,8 @@ private int getIconResId(Resources res, String icon,
248
239
/**
249
240
* Set notification color if its supported by the SDK.
250
241
*
251
- * @param notification
252
- * A Notification.Builder instance
253
- * @param settings
254
- * A JSON dict containing the color definition (red: FF0000)
242
+ * @param notification A Notification.Builder instance
243
+ * @param settings A JSON dict containing the color definition (red: FF0000)
255
244
*/
256
245
private void setColor (Notification .Builder notification ,
257
246
JSONObject settings ) {
@@ -276,4 +265,13 @@ private void setColor(Notification.Builder notification,
276
265
e .printStackTrace ();
277
266
}
278
267
}
268
+
269
+ /**
270
+ * Shared manager for the notification service.
271
+ */
272
+ private NotificationManager getNotificationManager () {
273
+ return (NotificationManager ) getSystemService (
274
+ Context .NOTIFICATION_SERVICE );
275
+ }
276
+
279
277
}
0 commit comments