aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/arslaancodes/mokuassistant
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/arslaancodes/mokuassistant')
-rw-r--r--app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java
index d30ed2e..7d381be 100644
--- a/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java
+++ b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java
@@ -3,6 +3,7 @@ package com.arslaancodes.mokuassistant;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
@@ -14,6 +15,7 @@ import androidx.core.app.NotificationCompat;
public class AssistantService extends Service {
private static final String TAG = "moku";
private static final String CHANNEL_ID = "moku_assistant_channel";
+ private static final String CHANNEL_NAME = "moku Assistant";
private static final int NOTIFICATION_ID = 1001;
@Override
@@ -27,16 +29,14 @@ public class AssistantService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "AssistantService started");
- Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle("moku Assistant").setContentText("listening...").setSmallIcon(android.R.drawable.ic_btn_speak_now).setPriority(NotificationCompat.PRIORITY_LOW).build();
-
+ Notification notification = buildNotification();
startForeground(NOTIFICATION_ID, notification);
startAssistant();
-
return START_STICKY;
}
- @Override
+ @Override
public void onDestroy() {
Log.i(TAG, "AssistantService destroyed");
stopAssistant();
@@ -52,10 +52,12 @@ public class AssistantService extends Service {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
- "moku Assistant",
+ CHANNEL_NAME,
NotificationManager.IMPORTANCE_LOW
);
channel.setDescription("Shows when moku Assistant is running");
+ channel.setShowBadge(false);
+
NotificationManager manager = getSystemService(NotificationManager.class);
if (manager != null) {
manager.createNotificationChannel(channel);
@@ -63,7 +65,25 @@ public class AssistantService extends Service {
}
}
- // JNI functions
+ private Notification buildNotification() {
+ Intent notificationIntent = new Intent(this, AssistantService.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(
+ this,
+ 0,
+ notificationIntent,
+ PendingIntent.FLAG_IMMUTABLE
+ );
+
+ return new NotificationCompat.Builder(this, CHANNEL_ID)
+ .setContentTitle("moku Assistant")
+ .setContentText("listening...")
+ .setSmallIcon(android.R.drawable.ic_btn_speak_now)
+ .setContentIntent(pendingIntent)
+ .setPriority(NotificationCompat.PRIORITY_LOW)
+ .setOngoing(true)
+ .build();
+ }
+
private static native void startAssistant();
private static native void stopAssistant();