notification support using libportal

This commit is contained in:
Julian Winkler
2024-03-17 11:05:42 +01:00
parent b14549e639
commit 45de09a191
9 changed files with 286 additions and 19 deletions

View File

@@ -1,13 +1,59 @@
package android.app;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
public class NotificationManager {
public void cancelAll() {}
public void notify(String tag, int id, Notification notification) {
System.out.println("notify(" + tag + ", " + id + ", " + notification + ") called");
long builder = nativeInitBuilder();
for (Notification.Action action : notification.actions) {
int intentType = -1;
String actionName = null;
String className = null;
if (action.intent != null) {
intentType = action.intent.type;
actionName = action.intent.intent.getAction();
className = action.intent.intent.getComponent() != null ? action.intent.intent.getComponent().getClassName() : null;
}
nativeAddAction(builder, action.title, intentType, actionName, className);
}
int intentType = -1;
String actionName = null;
String className = null;
if (notification.intent != null) {
intentType = notification.intent.type;
actionName = notification.intent.intent.getAction();
className = notification.intent.intent.getComponent() != null ? notification.intent.intent.getComponent().getClassName() : null;
}
nativeShowNotification(builder, id, notification.title, notification.text, intentType, actionName, className);
}
public void notify(int id, Notification notification) {
System.out.println("notify(" + id + ", " + notification + ") called");
notify(null, id, notification);
}
public void cancel(String tag, int id) {}
protected static void notificationActionCallback(int id, int intentType, String action, String className) {
Context context = Context.this_application;
Intent intent = new Intent(action);
if (className != null && !className.isEmpty()) {
intent.setComponent(new ComponentName(context, className));
}
if (intentType == 0) { // type Activity
context.startActivity(intent);
} else if (intentType == 1) { // type Service
context.startService(intent);
} else if (intentType == 2) { // type Broadcast
context.sendBroadcast(intent);
}
}
protected native long nativeInitBuilder();
protected native void nativeAddAction(long builder, String title, int intentType, String action, String className);
protected native void nativeShowNotification(long builder, int id, String title, String text, int intentType, String action, String className);
}