android_translation_layer/src/api-impl/android/app/NotificationManager.java

60 lines
2.3 KiB
Java
Raw Normal View History

2023-01-14 14:32:37 +01:00
package android.app;
2024-03-17 11:05:42 +01:00
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
2023-01-14 14:32:37 +01:00
public class NotificationManager {
public void cancelAll() {}
public void notify(String tag, int id, Notification notification) {
System.out.println("notify(" + tag + ", " + id + ", " + notification + ") called");
2024-03-17 11:05:42 +01:00
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, notification.iconPath, notification.ongoing, intentType, actionName, className);
}
2024-03-16 12:49:28 +01:00
public void notify(int id, Notification notification) {
2024-03-17 11:05:42 +01:00
notify(null, id, notification);
2024-03-16 12:49:28 +01:00
}
2024-03-17 11:05:42 +01:00
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, String iconPath, boolean ongoing, int intentType, String action, String className);
2023-01-14 14:32:37 +01:00
}