Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f7e965

Browse files
committed
add ability to specifiy an icon in the speech activation service
1 parent 8bc3811 commit 1f7e965

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

library/src/root/gast/speech/activation/SpeechActivationService.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package root.gast.speech.activation;
1717

1818
import root.gast.R;
19+
import android.annotation.SuppressLint;
1920
import android.app.Notification;
2021
import android.app.PendingIntent;
2122
import android.app.Service;
@@ -36,6 +37,8 @@ public class SpeechActivationService extends Service implements
3637
SpeechActivationListener
3738
{
3839
private static final String TAG = "SpeechActivationService";
40+
public static final String NOTIFICATION_ICON_RESOURCE_INTENT_KEY =
41+
"NOTIFICATION_ICON_RESOURCE_INTENT_KEY";
3942
public static final String ACTIVATION_TYPE_INTENT_KEY =
4043
"ACTIVATION_TYPE_INTENT_KEY";
4144
public static final String ACTIVATION_RESULT_INTENT_KEY =
@@ -124,11 +127,17 @@ public int onStartCommand(Intent intent, int flags, int startId)
124127

125128
private void startDetecting(Intent intent)
126129
{
130+
Log.d(TAG, "extras: " + intent.getExtras().toString());
131+
if (activator == null)
132+
{
133+
Log.d(TAG, "null activator");
134+
}
135+
127136
activator = getRequestedActivator(intent);
128137
Log.d(TAG, "started: " + activator.getClass().getSimpleName());
129138
isStarted = true;
130139
activator.detectActivation();
131-
startForeground(NOTIFICATION_ID, getNotification());
140+
startForeground(NOTIFICATION_ID, getNotification(intent));
132141
}
133142

134143
private SpeechActivator getRequestedActivator(Intent intent)
@@ -194,7 +203,8 @@ private void stopActivator()
194203
}
195204
}
196205

197-
private Notification getNotification()
206+
@SuppressLint("NewApi")
207+
private Notification getNotification(Intent intent)
198208
{
199209
// determine label based on the class
200210
String name = SpeechActivatorFactory.getLabel(this, activator);
@@ -207,11 +217,13 @@ private Notification getNotification()
207217
PendingIntent.getService(this, 0, makeServiceStopIntent(this),
208218
0);
209219

220+
int icon = intent.getIntExtra(NOTIFICATION_ICON_RESOURCE_INTENT_KEY, R.drawable.icon);
221+
210222
Notification notification;
211223
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
212224
{
213225
Notification.Builder builder = new Notification.Builder(this);
214-
builder.setSmallIcon(R.drawable.icon)
226+
builder.setSmallIcon(icon)
215227
.setWhen(System.currentTimeMillis()).setTicker(message)
216228
.setContentTitle(title).setContentText(message)
217229
.setContentIntent(pi);
@@ -220,7 +232,7 @@ private Notification getNotification()
220232
else
221233
{
222234
notification =
223-
new Notification(R.drawable.icon, message,
235+
new Notification(icon, message,
224236
System.currentTimeMillis());
225237
notification.setLatestEventInfo(this, title, message, pi);
226238
}

0 commit comments

Comments
 (0)