Skip to content

Commit cf23fde

Browse files
committed
notification bug fixed
1 parent 1e12e46 commit cf23fde

File tree

4 files changed

+27
-25
lines changed

4 files changed

+27
-25
lines changed

android/src/main/java/com/devsonflutter/reflex/notification/NotificationListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
public class NotificationListener extends NotificationListenerService {
3131

3232
private static final String TAG = ReflexPlugin.getPluginTag();
33-
private final Map<String, Object> autoReply = ReflexPlugin.autoReply;
3433

3534
@RequiresApi(api = VERSION_CODES.N)
3635
@Override
@@ -42,7 +41,6 @@ public void onNotificationPosted(StatusBarNotification notification) {
4241

4342
// Package name as title
4443
String packageName = notification.getPackageName();
45-
ReflexPlugin.debugPrint("Notification Received From: " + packageName);
4644

4745
// Extra Payload
4846
Bundle extras = notification.getNotification().extras;
@@ -70,6 +68,7 @@ public void onNotificationPosted(StatusBarNotification notification) {
7068
// Sending AutoReply
7169
if(NotificationUtils.canReply(notification))
7270
{
71+
final Map<String, Object> autoReply = ReflexPlugin.autoReply;
7372
String message = (String) autoReply.get("message");
7473
// Reply to notification
7574
new AutoReply(ReflexPlugin.context).sendReply(notification, packageName, title, message);

android/src/main/java/com/devsonflutter/reflex/notification/NotificationReceiver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ else if(packageNameList != null) {
6363
data.put("title", title);
6464
data.put("message", message);
6565

66+
ReflexPlugin.debugPrint("Notification Received From: " + packageName);
67+
6668
eventSink.success(data);
6769
}
6870
}

android/src/main/java/com/devsonflutter/reflex/notification/NotificationUtils.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public class NotificationUtils {
3737
public static String NOTIFICATION_MESSAGE = "notification_message";
3838
public static String NOTIFICATION_TITLE = "notification_title";
3939

40-
private static final Map<String, Object> autoReply = ReflexPlugin.autoReply;
41-
4240
private static final List<String> listeningPackageNameList = ReflexPlugin.packageNameList;
4341
private static final List<String> listeningExceptionPackageNameList = ReflexPlugin.packageNameExceptionList;
4442

@@ -114,47 +112,50 @@ public static String getTitleRaw(StatusBarNotification sbn) {
114112
static boolean canReply(StatusBarNotification notification) {
115113
String notificationPackageName = notification.getPackageName();
116114

117-
boolean isServiceEnabled = false;
118115
List<String> autoReplyPackageNameList = null;
119116

117+
final Map<String, Object> autoReply = ReflexPlugin.autoReply;
118+
120119
if(autoReply != null) {
121-
isServiceEnabled = true;
120+
122121
autoReplyPackageNameList = (List<String>) autoReply.get("packageNameList");
122+
123+
return isSupportedPackage(notificationPackageName,autoReplyPackageNameList) &&
124+
checkListeningAndReplyPackages(notificationPackageName,autoReplyPackageNameList) &&
125+
NotificationUtils.isNewNotification(notification);
123126
}
124127

125128
// If AutoReply object coming from flutter side is null, AutoReply feature is disabled
126-
if (!isServiceEnabled) return false;
127-
128-
return isSupportedPackage(notificationPackageName,autoReplyPackageNameList) &&
129-
checkListeningAndReplyPackages(notificationPackageName,autoReplyPackageNameList) &&
130-
NotificationUtils.isNewNotification(notification);
129+
return false;
131130
}
132131

133132
private static boolean checkListeningAndReplyPackages(String notificationPackageName,
134133
List<String> replyPackageNameList) {
135-
if(listeningPackageNameList == null && listeningExceptionPackageNameList == null && replyPackageNameList == null){
136-
return true;
137-
}else if(listeningPackageNameList == null && listeningExceptionPackageNameList == null){
138-
return replyPackageNameList.contains(notificationPackageName);
139-
}
140-
else if(listeningPackageNameList == null ){
141134

142-
return !listeningExceptionPackageNameList.contains(notificationPackageName);
143-
}
144-
else {
135+
if (listeningPackageNameList == null && listeningExceptionPackageNameList == null &&
136+
replyPackageNameList == null) {
145137
return true;
138+
} else if (listeningExceptionPackageNameList == null && listeningPackageNameList == null) {
139+
return replyPackageNameList.contains(notificationPackageName);
140+
} else if (listeningPackageNameList == null && replyPackageNameList == null) {
141+
return !listeningExceptionPackageNameList.contains(notificationPackageName);
142+
} else if (listeningPackageNameList == null) {
143+
return replyPackageNameList.contains(notificationPackageName);
146144
}
145+
146+
return listeningPackageNameList.contains(notificationPackageName);
147147
}
148148

149149
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
150-
private static boolean isSupportedPackage(String notificationPackageName, List<String> packageList) {
150+
private static boolean isSupportedPackage(String notificationPackageName,
151+
List<String> replyPackageNameList) {
151152
// If packageNameList coming from flutter is null,
152153
// then AutoReply is enabled for all packageNames
153-
if(packageList == null) {
154+
if(replyPackageNameList == null) {
154155
return true;
155156
}
156157

157158
// Check notification's package name contained in AutoReply's PackageNameList
158-
return packageList.contains(notificationPackageName);
159+
return replyPackageNameList.contains(notificationPackageName);
159160
}
160161
}

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class _MyAppState extends State<MyApp> {
2525
Reflex reflex = Reflex(
2626
debug: true,
2727
packageNameList: ["com.whatsapp", "com.tyup"],
28-
packageNameExceptionList: ["com.android.systemui"],
28+
packageNameExceptionList: ["com.facebook"],
2929
autoReply: AutoReply(
30-
packageNameList: ["com.whatsapp"],
30+
// packageNameList: ["com.whatsapp"],
3131
message: "[Reflex] This is an automated reply.",
3232
),
3333
);

0 commit comments

Comments
 (0)