You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
NotificationManager: store Intents in HashMap
This is needed for Intents with extras, because Parcelable serialization is not yet implemented
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
package android.app;
|
package android.app;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import android.app.Notification.MediaStyle;
|
import android.app.Notification.MediaStyle;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -11,6 +15,9 @@ public class NotificationManager {
|
|||||||
|
|
||||||
private static int mpris_notification_id = -1;
|
private static int mpris_notification_id = -1;
|
||||||
|
|
||||||
|
// store Intents in map, as long as Parcelable serialization is not yet implemented
|
||||||
|
private static Map<Integer, Intent> intents = new HashMap<Integer, Intent>();
|
||||||
|
|
||||||
public void cancelAll() {}
|
public void cancelAll() {}
|
||||||
|
|
||||||
public void notify(String tag, int id, Notification notification) {
|
public void notify(String tag, int id, Notification notification) {
|
||||||
@@ -42,6 +49,7 @@ public class NotificationManager {
|
|||||||
intentType = notification.intent.type;
|
intentType = notification.intent.type;
|
||||||
actionName = notification.intent.intent.getAction();
|
actionName = notification.intent.intent.getAction();
|
||||||
className = notification.intent.intent.getComponent() != null ? notification.intent.intent.getComponent().getClassName() : null;
|
className = notification.intent.intent.getComponent() != null ? notification.intent.intent.getComponent().getClassName() : null;
|
||||||
|
intents.put(id, notification.intent.intent);
|
||||||
}
|
}
|
||||||
nativeShowNotification(builder, id, notification.title, notification.text, notification.iconPath, notification.ongoing, intentType, actionName, className);
|
nativeShowNotification(builder, id, notification.title, notification.text, notification.iconPath, notification.ongoing, intentType, actionName, className);
|
||||||
}
|
}
|
||||||
@@ -72,9 +80,14 @@ public class NotificationManager {
|
|||||||
|
|
||||||
protected static void notificationActionCallback(int id, int intentType, String action, String className) {
|
protected static void notificationActionCallback(int id, int intentType, String action, String className) {
|
||||||
Context context = Context.this_application;
|
Context context = Context.this_application;
|
||||||
Intent intent = new Intent(action);
|
action = "".equals(action) ? null : action;
|
||||||
if (className != null && !className.isEmpty()) {
|
className = "".equals(className) ? null : className;
|
||||||
intent.setComponent(new ComponentName(context, className));
|
Intent intent = intents.remove(id);
|
||||||
|
if (intent == null || !Objects.equals(action, intent.getAction()) || !Objects.equals(className, intent.getComponent().getClassName())) {
|
||||||
|
intent = new Intent(action);
|
||||||
|
if (className != null) {
|
||||||
|
intent.setComponent(new ComponentName(context, className));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (intentType == 0) { // type Activity
|
if (intentType == 0) { // type Activity
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|||||||
Reference in New Issue
Block a user