refactor: archive GUI clients; keep minimal TUI with hooks/API
Move Qt/Tauri/full Web SPA under archive/, ship hermit as CLI/TUI plus libcstcore and cst-webui/1 HTTP+SSE (turn lifecycle hooks, capabilities). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- The APK's manifest (QT_ANDROID_PACKAGE_SOURCE_DIR in app/CMakeLists.txt):
|
||||
androiddeployqt copies this file and res/ into its gradle project and
|
||||
fills in the INSERT_* placeholders below (version code and name, library
|
||||
name, app arguments). An XML comment may not contain a double hyphen, so
|
||||
the placeholder syntax is only spelled out in the attributes themselves.
|
||||
|
||||
The SDK levels are not here on purpose: they come from
|
||||
QT_ANDROID_MIN_SDK_VERSION and QT_ANDROID_TARGET_SDK_VERSION in
|
||||
app/CMakeLists.txt, and androiddeployqt writes them into the generated
|
||||
gradle.properties. The app name and icon come from res/ next to this
|
||||
file (values/strings.xml, drawable/ic_launcher.xml).
|
||||
|
||||
WHAT THIS APP IS: the engine runs in this process (no server, no port) and
|
||||
writes everything (workspace, session store, settings, credentials) under
|
||||
the app's own data directory, which main.cpp points the engine at (see
|
||||
androidRoot() there).
|
||||
|
||||
Permissions: INTERNET for the providers the user configures,
|
||||
POST_NOTIFICATIONS for the app's notification_send tool (Android 13+
|
||||
asks at runtime; the tool stays hidden until it is granted), the
|
||||
foreground-service permissions with WAKE_LOCK for the service that keeps
|
||||
a turn going while the phone is in a pocket (CstService.java), and
|
||||
MANAGE_EXTERNAL_STORAGE ("all files access", Android 11+) so the engine
|
||||
can read a path in shared storage that a task names rather than picks:
|
||||
Android only offers the Settings screen for it, so main.cpp opens that
|
||||
once and everything still works without it: what the system picker (SAF)
|
||||
hands over is copied into the app's own directory (AttachFile.java). No
|
||||
cleartext traffic: every provider URL is https. -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="xyz.whcself.cstagent"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="-- %%INSERT_VERSION_CODE%% --"
|
||||
android:versionName="-- %%INSERT_VERSION_NAME%% --">
|
||||
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<!-- "All files access": without it the engine can only read the app's own
|
||||
directory, so a task that names a file in shared storage cannot be
|
||||
answered. Android 11+ has no runtime dialog for it, only the Settings
|
||||
screen (AttachFile.java opens it once). Files the user picks work
|
||||
either way: their content:// grant is copied into the app first. -->
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:smallScreens="true" />
|
||||
|
||||
<application
|
||||
android:name="org.qtproject.qt.android.bindings.QtApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:allowBackup="true"
|
||||
android:hardwareAccelerated="true"
|
||||
android:enableOnBackInvokedCallback="false">
|
||||
|
||||
<activity
|
||||
android:name="org.qtproject.qt.android.bindings.QtActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|keyboard|keyboardHidden|navigation|density|mcc|mnc"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="unspecified"
|
||||
android:exported="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="-- %%INSERT_APP_LIB_NAME%% --" />
|
||||
<meta-data
|
||||
android:name="android.app.arguments"
|
||||
android:value="-- %%INSERT_APP_ARGUMENTS%% --" />
|
||||
</activity>
|
||||
|
||||
<!-- The share tool hands a file out of the workspace, and a file
|
||||
crossing an app boundary has to travel as a content:// uri. This
|
||||
is Qt's own provider (androidx.core.content.FileProvider, paths
|
||||
from res/xml/qtprovider_paths.xml): its files-path is the app's
|
||||
files directory, which is where the workspace lives. -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.qtprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/qtprovider_paths" />
|
||||
</provider>
|
||||
|
||||
<!-- A turn can outlive the screen: while one is running the front end
|
||||
starts this service (AgentCore::send -> app::holdForeground), which
|
||||
makes the process a foreground one, so Android neither freezes nor
|
||||
kills it in the background, and takes a partial wake lock so the
|
||||
CPU keeps going with the phone in a pocket. dataSync is the type
|
||||
that fits "the app is finishing some work". -->
|
||||
<service
|
||||
android:name="xyz.whcself.cstagent.CstService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Launcher icon: the terminal prompt the app is about (">_"), the window's
|
||||
own colors (bg #12161a, accent #5cc0f0, faint #8d959c). A vector drawable
|
||||
works from API 24 up; a proper adaptive icon (mipmap-anydpi-v26 + a PNG
|
||||
fallback) is polish for later. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
|
||||
<path
|
||||
android:fillColor="#12161a"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#5cc0f0"
|
||||
android:strokeWidth="7"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"
|
||||
android:pathData="M32,38 L52,54 L32,70" />
|
||||
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="#8d959c"
|
||||
android:strokeWidth="7"
|
||||
android:strokeLineCap="round"
|
||||
android:pathData="M58,74 L78,74" />
|
||||
</vector>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- The name under the launcher icon. -->
|
||||
<resources>
|
||||
<string name="app_name">CST-agent</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,189 @@
|
||||
package xyz.whcself.cstagent;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.provider.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/* What the user picks in the system file chooser comes back as a content://
|
||||
* URI, and the engine opens files by path -- so the bytes are copied into the
|
||||
* app's own directory first. That copy needs no permission at all (the grant
|
||||
* travels with the URI), which is what makes picking work on a phone that
|
||||
* grants nothing else.
|
||||
*
|
||||
* The "all files access" below is a different thing: it is what lets the
|
||||
* engine read /sdcard by path afterwards (a model that opens a file the user
|
||||
* names rather than picks). Android 11+ has no runtime dialog for it -- only
|
||||
* the Settings screen -- so it is a request, not a demand: everything works
|
||||
* without it, one file at a time.
|
||||
*
|
||||
* Qt swallows a Java exception (it comes back as a null object), so every
|
||||
* method catches its own and answers with a reason instead.
|
||||
*/
|
||||
public final class AttachFile {
|
||||
private AttachFile() {}
|
||||
|
||||
private static final long MAX_BYTES = 256L * 1024 * 1024;
|
||||
|
||||
public static boolean isContent(String s) {
|
||||
return s != null && s.startsWith("content:");
|
||||
}
|
||||
|
||||
/* content://<uri> -> the path of a copy inside destDir; "" when the string
|
||||
* is already a path; "error: ..." when the copy failed. */
|
||||
public static String materialize(Context ctx, String pathOrUri, String destDir) {
|
||||
if (pathOrUri == null || pathOrUri.isEmpty())
|
||||
return "error: no file was picked";
|
||||
if (!isContent(pathOrUri))
|
||||
return "";
|
||||
try {
|
||||
if (ctx == null)
|
||||
return "error: no Android context";
|
||||
final Uri uri = Uri.parse(pathOrUri);
|
||||
String name = displayName(ctx, uri);
|
||||
if (name == null || name.trim().isEmpty())
|
||||
name = uri.getLastPathSegment();
|
||||
name = sanitize(name);
|
||||
File dir = new File(destDir);
|
||||
if (!dir.isDirectory() && !dir.mkdirs())
|
||||
return "error: cannot use " + destDir;
|
||||
File out = unique(dir, name);
|
||||
final ContentResolver cr = ctx.getContentResolver();
|
||||
final InputStream in = cr.openInputStream(uri);
|
||||
if (in == null)
|
||||
return "error: the picker gave no data for that file";
|
||||
long total = 0;
|
||||
try {
|
||||
final OutputStream os = new FileOutputStream(out);
|
||||
try {
|
||||
final byte[] buf = new byte[64 * 1024];
|
||||
int n;
|
||||
while ((n = in.read(buf)) > 0) {
|
||||
total += n;
|
||||
if (total > MAX_BYTES) {
|
||||
os.close();
|
||||
in.close();
|
||||
out.delete();
|
||||
return "error: that file is larger than 256 MB";
|
||||
}
|
||||
os.write(buf, 0, n);
|
||||
}
|
||||
} finally {
|
||||
os.close();
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
if (total == 0) {
|
||||
out.delete();
|
||||
return "error: that file is empty";
|
||||
}
|
||||
return out.getAbsolutePath();
|
||||
} catch (Throwable t) {
|
||||
return "error: cannot read the picked file: " + t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Android 11+ keeps "all files access" in a special app-op; older systems
|
||||
* have no such gate. */
|
||||
public static boolean hasAllFilesAccess(Context ctx) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT < 30)
|
||||
return true;
|
||||
return Environment.isExternalStorageManager();
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* The Settings screen Android requires for it. "" when it was opened. */
|
||||
public static String requestAllFilesAccess(Context ctx) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT < 30 || ctx == null)
|
||||
return "";
|
||||
if (Environment.isExternalStorageManager())
|
||||
return "";
|
||||
final Intent intent = new Intent(
|
||||
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
Uri.parse("package:" + ctx.getPackageName()));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
ctx.startActivity(intent);
|
||||
} catch (ActivityNotFoundException notFound) {
|
||||
final Intent all = new Intent(
|
||||
Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
||||
all.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
ctx.startActivity(all);
|
||||
}
|
||||
return "";
|
||||
} catch (Throwable t) {
|
||||
return "cannot open the storage settings: " + t;
|
||||
}
|
||||
}
|
||||
|
||||
private static String displayName(Context ctx, Uri uri) {
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = ctx.getContentResolver().query(uri,
|
||||
new String[] { OpenableColumns.DISPLAY_NAME }, null, null,
|
||||
null);
|
||||
if (c != null && c.moveToFirst()) {
|
||||
final int i = c.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if (i >= 0)
|
||||
return c.getString(i);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
/* fall back to the last path segment */
|
||||
} finally {
|
||||
if (c != null)
|
||||
c.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* A plain file name: no separators, no traversal, no control bytes. */
|
||||
private static String sanitize(String name) {
|
||||
if (name == null || name.isEmpty())
|
||||
return "picked.bin";
|
||||
final StringBuilder b = new StringBuilder();
|
||||
for (int i = 0; i < name.length() && b.length() < 120; i++) {
|
||||
final char ch = name.charAt(i);
|
||||
if (ch == '/' || ch == '\\' || ch < 0x20)
|
||||
b.append('_');
|
||||
else
|
||||
b.append(ch);
|
||||
}
|
||||
String s = b.toString();
|
||||
while (s.startsWith("."))
|
||||
s = s.substring(1);
|
||||
if (s.isEmpty())
|
||||
return "picked.bin";
|
||||
return s;
|
||||
}
|
||||
|
||||
private static File unique(File dir, String name) {
|
||||
File f = new File(dir, name);
|
||||
if (!f.exists())
|
||||
return f;
|
||||
final int dot = name.lastIndexOf('.');
|
||||
final String stem = dot > 0 ? name.substring(0, dot) : name;
|
||||
final String ext = dot > 0 ? name.substring(dot) : "";
|
||||
for (int i = 2; i < 1000; i++) {
|
||||
f = new File(dir, stem + "-" + i + ext);
|
||||
if (!f.exists())
|
||||
return f;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package xyz.whcself.cstagent;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
|
||||
/**
|
||||
* The service that keeps a turn running while the app is not on screen.
|
||||
*
|
||||
* A phone freezes an app it cannot see (and may kill it), so a turn that takes
|
||||
* minutes -- a build, a long web fetch, a provider that thinks -- dies in the
|
||||
* pocket. While one is going, AgentCore::send() starts this service through
|
||||
* app::holdForeground(); being a foreground service makes the process one
|
||||
* Android does not touch, and the partial wake lock keeps the CPU awake with
|
||||
* the screen off. turnFinished() stops it again (app::releaseForeground()), so
|
||||
* the permanent notification exists exactly as long as the work does.
|
||||
*
|
||||
* Started with an explicit component (AndroidTools.cpp builds the Intent), no
|
||||
* intent filter: nothing outside the app can start it.
|
||||
*/
|
||||
public class CstService extends Service {
|
||||
/** Same channel the notification_send tool uses: one place in settings. */
|
||||
private static final String CHANNEL_ID = "cst-agent";
|
||||
private static final int NOTE_ID = 2;
|
||||
private static final String ACTION_STOP = "xyz.whcself.cstagent.STOP";
|
||||
/** A turn that runs longer than this is stuck; the lock must not outlive it. */
|
||||
private static final long WAKE_LOCK_TIMEOUT_MS = 30 * 60 * 1000L;
|
||||
|
||||
private PowerManager.WakeLock wake;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent != null && ACTION_STOP.equals(intent.getAction())) {
|
||||
stopEverything();
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
String text = intent == null ? null : intent.getStringExtra("text");
|
||||
try {
|
||||
startForeground(NOTE_ID, buildNote(text));
|
||||
} catch (Throwable t) {
|
||||
/* Android 12+ refuses a foreground start from the background: the
|
||||
* turn then simply runs without the protection rather than not at
|
||||
* all. Nothing to show the user here -- the turn's own result is
|
||||
* what matters. */
|
||||
stopSelf();
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
acquireWake();
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
releaseWake();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void stopEverything() {
|
||||
releaseWake();
|
||||
if (Build.VERSION.SDK_INT >= 24)
|
||||
stopForeground(STOP_FOREGROUND_REMOVE);
|
||||
else
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
private void acquireWake() {
|
||||
try {
|
||||
if (wake == null) {
|
||||
PowerManager pm =
|
||||
(PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (pm == null)
|
||||
return;
|
||||
wake = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||
"cst-agent:turn");
|
||||
wake.setReferenceCounted(false);
|
||||
}
|
||||
wake.acquire(WAKE_LOCK_TIMEOUT_MS);
|
||||
} catch (Throwable ignored) {
|
||||
/* no wake lock: the turn still runs while the screen is on */
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseWake() {
|
||||
try {
|
||||
if (wake != null && wake.isHeld())
|
||||
wake.release();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/** "the agent is working: <first line of the prompt>", tapping opens it. */
|
||||
private Notification buildNote(String text) {
|
||||
Context ctx = getApplicationContext();
|
||||
NotificationManager manager =
|
||||
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (manager != null && Build.VERSION.SDK_INT >= 26) {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
CHANNEL_ID, "CST-agent", NotificationManager.IMPORTANCE_LOW);
|
||||
channel.setDescription("A turn is running");
|
||||
manager.createNotificationChannel(channel);
|
||||
}
|
||||
Notification.Builder builder = Build.VERSION.SDK_INT >= 26
|
||||
? new Notification.Builder(ctx, CHANNEL_ID)
|
||||
: new Notification.Builder(ctx);
|
||||
builder.setContentTitle("CST-agent is working")
|
||||
.setSmallIcon(smallIcon())
|
||||
.setOngoing(true)
|
||||
.setShowWhen(false);
|
||||
if (text != null && !text.isEmpty())
|
||||
builder.setContentText(text);
|
||||
Intent open = ctx.getPackageManager().getLaunchIntentForPackage(ctx.getPackageName());
|
||||
if (open != null) {
|
||||
open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
builder.setContentIntent(PendingIntent.getActivity(ctx, 0, open,
|
||||
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/** A framework drawable first (the same order the tool uses), then the app's. */
|
||||
private int smallIcon() {
|
||||
int icon = getResources().getIdentifier("ic_dialog_info", "drawable", "android");
|
||||
if (icon == 0)
|
||||
icon = getResources().getIdentifier("stat_notify_chat", "drawable", "android");
|
||||
if (icon == 0)
|
||||
icon = getApplicationInfo().icon;
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package xyz.whcself.cstagent;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* The notification behind the engine's notification_send tool.
|
||||
*
|
||||
* It lives in Java because a Java exception is invisible to C++ by the time
|
||||
* Qt's JNI wrapper is done with the call: Notification.Builder.build() can
|
||||
* throw (a small icon Android refuses, a channel it does not know) and the
|
||||
* JNI call then simply returns null -- the tool could only say "failed, no
|
||||
* exception detail" on a device where the phone's own shade never saw
|
||||
* anything. Catching it here turns the failure into the line the tool shows.
|
||||
*
|
||||
* Called from app/src/platform/android/AndroidTools.cpp through QJniObject.
|
||||
* androiddeployqt copies this file with the rest of the package source
|
||||
* (QT_ANDROID_PACKAGE_SOURCE_DIR, app/android/) and Qt's Gradle template adds
|
||||
* "src" to java.srcDirs, so no build script change is needed for a file
|
||||
* added here.
|
||||
*/
|
||||
public final class Notifier {
|
||||
private Notifier() {}
|
||||
|
||||
/**
|
||||
* Post one notification. An empty channelId means an API below 26, which
|
||||
* has no channels. Returns "" when it went out, the Java failure
|
||||
* otherwise (class name and message), so the tool result can name it.
|
||||
*/
|
||||
public static String post(Context ctx, String channelId, String title,
|
||||
String text, int iconId, Intent tap, int id) {
|
||||
try {
|
||||
Notification.Builder builder = channelId == null || channelId.isEmpty()
|
||||
? new Notification.Builder(ctx)
|
||||
: new Notification.Builder(ctx, channelId);
|
||||
builder.setContentTitle(title).setContentText(text).setSmallIcon(iconId);
|
||||
if (tap != null) {
|
||||
tap.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PendingIntent pending = PendingIntent.getActivity(
|
||||
ctx, 0, tap,
|
||||
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
builder.setContentIntent(pending);
|
||||
}
|
||||
NotificationManager manager = (NotificationManager)
|
||||
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (manager == null)
|
||||
return "no NotificationManager";
|
||||
manager.notify(id, builder.build());
|
||||
return "";
|
||||
} catch (Throwable t) {
|
||||
String message = t.getMessage();
|
||||
return t.getClass().getSimpleName()
|
||||
+ (message == null || message.isEmpty() ? "" : ": " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user