diff options
| author | Arslaan Pathan <[email protected]> | 2026-08-16 20:33:17 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-08-16 20:33:17 +1200 |
| commit | 31a371d3a76f80df501210b1b3ea59b86cfecbf1 (patch) | |
| tree | 735a81c4a02d1c5bf0514d43d07f1ab3255bc3ce /app/src/main/java/com | |
| parent | 31dd56575a7aad761efcea7bcddd0377743aecfe (diff) | |
| download | moku-assistant-31a371d3a76f80df501210b1b3ea59b86cfecbf1.tar.xz moku-assistant-31a371d3a76f80df501210b1b3ea59b86cfecbf1.zip | |
[fix] use the activity's classloader to fix JNI and also create notification channel
Diffstat (limited to 'app/src/main/java/com')
| -rw-r--r-- | app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java | 32 |
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(); |
