Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</intent-filter>

<!-- "Ask Webmini" in text selection menu (long-press text in any app) -->
<intent-filter android:label="Ask Webmini">
<intent-filter android:label="@string/ask_webmini">
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
Expand All @@ -132,5 +132,33 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<!-- Eligible as the default digital assistant. The session opens MainActivity. -->
<service
android:name=".assistant.WebminiVoiceInteractionService"
android:label="@string/app_name"
android:permission="android.permission.BIND_VOICE_INTERACTION"
android:exported="true">
<meta-data
android:name="android.voice_interaction"
android:resource="@xml/assistant_voice_interaction" />
<intent-filter>
<action android:name="android.service.voice.VoiceInteractionService" />
</intent-filter>
</service>

<service
android:name=".assistant.WebminiSessionService"
android:permission="android.permission.BIND_VOICE_INTERACTION"
android:exported="true" />

<service
android:name=".assistant.WebminiRecognitionService"
android:permission="android.permission.BIND_RECOGNITION_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.speech.RecognitionService" />
</intent-filter>
</service>
</application>
</manifest>
37 changes: 37 additions & 0 deletions app/src/main/java/com/webmini/app/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.webmini.app;

import android.app.Activity;
import android.app.role.RoleManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -9,6 +10,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.Button;
Expand Down Expand Up @@ -51,6 +53,17 @@ protected void onCreate(Bundle savedInstanceState) {
});
}

// ─── Digital assistant ────────────────────────────────────────────
Button assistantButton = findViewById(R.id.assistant_button);
if (assistantButton != null) {
assistantButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openAssistantSettings();
}
});
}

// ─── WebView Manager button ───────────────────────────────────────
Button webviewManagerButton = findViewById(R.id.webview_manager_button);
if (webviewManagerButton != null) {
Expand Down Expand Up @@ -174,6 +187,30 @@ public void onClick(DialogInterface d, int which) {
});
}

/**
* API 29+ asks the system to grant ROLE_ASSISTANT. Older versions open
* the voice-input settings screen, which includes the assistant picker.
*/
private void openAssistantSettings() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
RoleManager roleManager = (RoleManager) getSystemService(RoleManager.class);
if (roleManager != null && roleManager.isRoleAvailable(RoleManager.ROLE_ASSISTANT)) {
try {
startActivity(roleManager.createRequestRoleIntent(RoleManager.ROLE_ASSISTANT));
return;
} catch (Exception e) {
Log.w("SettingsActivity", "Assistant role request failed", e);
}
}
}
try {
startActivity(new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS));
} catch (Exception e) {
Log.w("SettingsActivity", "Voice input settings unavailable", e);
Toast.makeText(this, R.string.assistant_settings_unavailable, Toast.LENGTH_LONG).show();
}
}

/** Open a URL in the user's default browser. */
private void openUrl(String url) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.webmini.app.assistant;

import android.content.Intent;
import android.os.RemoteException;
import android.speech.RecognitionService;
import android.speech.SpeechRecognizer;

/**
* VoiceInteractionService requires a recognition service in the same package.
* Webmini does not record or transcribe audio; listening ends immediately.
*/
public class WebminiRecognitionService extends RecognitionService {
@Override
protected void onStartListening(Intent recognizerIntent, Callback listener) {
try {
listener.error(SpeechRecognizer.ERROR_CLIENT);
} catch (RemoteException ignored) {
}
}

@Override
protected void onCancel(Callback listener) {
}

@Override
protected void onStopListening(Callback listener) {
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/webmini/app/assistant/WebminiSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.webmini.app.assistant;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.service.voice.VoiceInteractionSession;

import com.webmini.app.MainActivity;

/**
* Assistant invocation opens MainActivity. A fresh process loads the AI Mode
* URL from MainActivity; an already-running task is brought forward.
*/
public class WebminiSession extends VoiceInteractionSession {

public WebminiSession(WebminiSessionService service) {
super(service);
}

@Override
public void onShow(Bundle args, int showFlags) {
super.onShow(args, showFlags);
Intent launch = new Intent(getContext(), MainActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
startAssistantActivity(launch);
} else {
getContext().startActivity(launch);
}
hide();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.webmini.app.assistant;

import android.os.Bundle;
import android.service.voice.VoiceInteractionSession;
import android.service.voice.VoiceInteractionSessionService;

public class WebminiSessionService extends VoiceInteractionSessionService {
@Override
public VoiceInteractionSession onNewSession(Bundle args) {
return new WebminiSession(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.webmini.app.assistant;

import android.service.voice.VoiceInteractionService;

/**
* Presence of this service is what puts Webmini in the system
* digital-assistant list. The session opens MainActivity; there is no
* voice UI of its own.
*/
public class WebminiVoiceInteractionService extends VoiceInteractionService {
}
78 changes: 78 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,84 @@
</LinearLayout>
</com.google.android.material.card.MaterialCardView>

<!-- ============ ASSISTANT SECTION ============ -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="10dp"
android:text="@string/assistant_section"
android:textColor="?attr/colorPrimary"
android:textSize="13sp"
android:textStyle="bold"
android:letterSpacing="0.08" />

<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
app:cardBackgroundColor="?attr/colorSurfaceContainerLow"
app:cardCornerRadius="20dp"
app:cardElevation="0dp"
app:strokeColor="?attr/colorOutlineVariant"
app:strokeWidth="1dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="64dp"
android:orientation="horizontal"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/assistant_title"
android:textColor="?attr/colorOnSurface"
android:textSize="16sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="@string/assistant_summary"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="12sp" />

</LinearLayout>

</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/assistant_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="4dp"
android:text="@string/assistant_button"
app:cornerRadius="12dp"
style="@style/Widget.Material3.Button.TonalButton" />

</LinearLayout>
</com.google.android.material.card.MaterialCardView>

<!-- ============ WEBVIEW SECTION ============ -->
<TextView
android:layout_width="wrap_content"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<resources>
<string name="app_name">Webmini</string>
<string name="settings_title">Webmini Settings</string>
<string name="ask_webmini">Ask Webmini</string>

<string name="assistant_section">Assistant</string>
<string name="assistant_title">Digital assistant</string>
<string name="assistant_summary">Open Webmini from the assistant gesture</string>
<string name="assistant_button">Set as assistant</string>
<string name="assistant_settings_unavailable">Assistant settings are not available on this device</string>

<!-- WebView Manager -->
<string name="webview_manager">WebView Manager</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/assistant_voice_interaction.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<voice-interaction-service xmlns:android="http://schemas.android.com/apk/res/android"
android:sessionService="com.webmini.app.assistant.WebminiSessionService"
android:recognitionService="com.webmini.app.assistant.WebminiRecognitionService"
android:supportsAssist="true"
android:supportsLaunchVoiceAssistFromKeyguard="true" />