aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/arslaancodes/mokuassistant
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-08-16 19:55:22 +1200
committerArslaan Pathan <[email protected]>2026-08-16 19:55:22 +1200
commit9c48fa24fb5dac9afb44785415ebd82385483a29 (patch)
tree60f27b0ab727ff18ec0a9090485e0b3b964113d2 /app/src/main/java/com/arslaancodes/mokuassistant
parent10656167c4fb03ec39e40dbc9354dd592bec8f9d (diff)
downloadmoku-assistant-9c48fa24fb5dac9afb44785415ebd82385483a29.tar.xz
moku-assistant-9c48fa24fb5dac9afb44785415ebd82385483a29.zip
[impl] add AssistantService foreground service
Diffstat (limited to 'app/src/main/java/com/arslaancodes/mokuassistant')
-rw-r--r--app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java
new file mode 100644
index 0000000..d30ed2e
--- /dev/null
+++ b/app/src/main/java/com/arslaancodes/mokuassistant/AssistantService.java
@@ -0,0 +1,73 @@
+package com.arslaancodes.mokuassistant;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
+import android.content.Intent;
+import android.os.Build;
+import android.os.IBinder;
+import android.util.Log;
+
+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 int NOTIFICATION_ID = 1001;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ createNotificationChannel();
+ Log.i(TAG, "AssistantService created");
+ }
+
+ @Override
+ 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();
+
+ startForeground(NOTIFICATION_ID, notification);
+
+ startAssistant();
+
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ Log.i(TAG, "AssistantService destroyed");
+ stopAssistant();
+ super.onDestroy();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ private void createNotificationChannel() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel channel = new NotificationChannel(
+ CHANNEL_ID,
+ "moku Assistant",
+ NotificationManager.IMPORTANCE_LOW
+ );
+ channel.setDescription("Shows when moku Assistant is running");
+ NotificationManager manager = getSystemService(NotificationManager.class);
+ if (manager != null) {
+ manager.createNotificationChannel(channel);
+ }
+ }
+ }
+
+ // JNI functions
+ private static native void startAssistant();
+ private static native void stopAssistant();
+
+ static {
+ System.loadLibrary("moku");
+ }
+}