16
16
package root .gast .speech .activation ;
17
17
18
18
import root .gast .R ;
19
+ import android .annotation .SuppressLint ;
19
20
import android .app .Notification ;
20
21
import android .app .PendingIntent ;
21
22
import android .app .Service ;
@@ -36,6 +37,8 @@ public class SpeechActivationService extends Service implements
36
37
SpeechActivationListener
37
38
{
38
39
private static final String TAG = "SpeechActivationService" ;
40
+ public static final String NOTIFICATION_ICON_RESOURCE_INTENT_KEY =
41
+ "NOTIFICATION_ICON_RESOURCE_INTENT_KEY" ;
39
42
public static final String ACTIVATION_TYPE_INTENT_KEY =
40
43
"ACTIVATION_TYPE_INTENT_KEY" ;
41
44
public static final String ACTIVATION_RESULT_INTENT_KEY =
@@ -124,11 +127,17 @@ public int onStartCommand(Intent intent, int flags, int startId)
124
127
125
128
private void startDetecting (Intent intent )
126
129
{
130
+ Log .d (TAG , "extras: " + intent .getExtras ().toString ());
131
+ if (activator == null )
132
+ {
133
+ Log .d (TAG , "null activator" );
134
+ }
135
+
127
136
activator = getRequestedActivator (intent );
128
137
Log .d (TAG , "started: " + activator .getClass ().getSimpleName ());
129
138
isStarted = true ;
130
139
activator .detectActivation ();
131
- startForeground (NOTIFICATION_ID , getNotification ());
140
+ startForeground (NOTIFICATION_ID , getNotification (intent ));
132
141
}
133
142
134
143
private SpeechActivator getRequestedActivator (Intent intent )
@@ -194,7 +203,8 @@ private void stopActivator()
194
203
}
195
204
}
196
205
197
- private Notification getNotification ()
206
+ @ SuppressLint ("NewApi" )
207
+ private Notification getNotification (Intent intent )
198
208
{
199
209
// determine label based on the class
200
210
String name = SpeechActivatorFactory .getLabel (this , activator );
@@ -207,11 +217,13 @@ private Notification getNotification()
207
217
PendingIntent .getService (this , 0 , makeServiceStopIntent (this ),
208
218
0 );
209
219
220
+ int icon = intent .getIntExtra (NOTIFICATION_ICON_RESOURCE_INTENT_KEY , R .drawable .icon );
221
+
210
222
Notification notification ;
211
223
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB )
212
224
{
213
225
Notification .Builder builder = new Notification .Builder (this );
214
- builder .setSmallIcon (R . drawable . icon )
226
+ builder .setSmallIcon (icon )
215
227
.setWhen (System .currentTimeMillis ()).setTicker (message )
216
228
.setContentTitle (title ).setContentText (message )
217
229
.setContentIntent (pi );
@@ -220,7 +232,7 @@ private Notification getNotification()
220
232
else
221
233
{
222
234
notification =
223
- new Notification (R . drawable . icon , message ,
235
+ new Notification (icon , message ,
224
236
System .currentTimeMillis ());
225
237
notification .setLatestEventInfo (this , title , message , pi );
226
238
}
0 commit comments