Skip to content

Commit dc32f66

Browse files
glmdevpatri9ck
andauthored
Include app package name in notification data (#52)
* Include app package name in notification message * Use requireContext() --------- Co-authored-by: Patrick Zwick <patri9ck@gmail.com>
1 parent 2c37b25 commit dc32f66

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

app/src/main/java/dev/patri9ck/a2ln/notification/NotificationSender.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public KeptLog sendParsedNotification(ParsedNotification parsedNotification) {
112112
zMsg.add(parsedNotification.getAppName());
113113
zMsg.add(parsedNotification.getTitle());
114114
zMsg.add(parsedNotification.getText());
115+
zMsg.add(parsedNotification.getPackageName());
115116

116117
parsedNotification.getIcon().ifPresent(zMsg::add);
117118

app/src/main/java/dev/patri9ck/a2ln/notification/ParsedNotification.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ public class ParsedNotification {
3939
private final String appName;
4040
private final String title;
4141
private final String text;
42+
private final String packageName;
4243
private final byte[] icon;
4344

44-
public ParsedNotification(String appName, String title, String text, byte[] icon) {
45+
public ParsedNotification(String appName, String title, String text, String packageName, byte[] icon) {
4546
this.appName = appName;
4647
this.title = title;
4748
this.text = text;
4849
this.icon = icon;
50+
this.packageName = packageName;
4951
}
5052

51-
public ParsedNotification(String appName, String title, String text) {
52-
this(appName, title, text, null);
53+
public ParsedNotification(String appName, String title, String text, String packageName) {
54+
this(appName, title, text, packageName, null);
5355
}
5456

5557
public static Optional<ParsedNotification> parseNotification(StatusBarNotification statusBarNotification, Context context) {
@@ -62,7 +64,8 @@ public static Optional<ParsedNotification> parseNotification(StatusBarNotificati
6264
return Optional.empty();
6365
}
6466

65-
String appName = Util.getAppName(context.getPackageManager(), statusBarNotification.getPackageName()).orElse("");
67+
String packageName = statusBarNotification.getPackageName();
68+
String appName = Util.getAppName(context.getPackageManager(), packageName).orElse("");
6669

6770
Icon largeIcon = notification.getLargeIcon();
6871

@@ -73,14 +76,14 @@ public static Optional<ParsedNotification> parseNotification(StatusBarNotificati
7376
if (drawable instanceof BitmapDrawable) {
7477
((BitmapDrawable) drawable).getBitmap().compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
7578

76-
return Optional.of(new ParsedNotification(appName, title, text, byteArrayOutputStream.toByteArray()));
79+
return Optional.of(new ParsedNotification(appName, title, text, packageName, byteArrayOutputStream.toByteArray()));
7780
}
7881
} catch (IOException exception) {
7982
Log.e(TAG, "Failed to convert picture to bytes", exception);
8083
}
8184
}
8285

83-
return Optional.of(new ParsedNotification(appName, title, text));
86+
return Optional.of(new ParsedNotification(appName, title, text, packageName));
8487
}
8588

8689
public String getAppName() {
@@ -95,6 +98,10 @@ public String getText() {
9598
return text;
9699
}
97100

101+
public String getPackageName() {
102+
return packageName;
103+
}
104+
98105
public Optional<byte[]> getIcon() {
99106
return Optional.ofNullable(icon);
100107
}

app/src/main/java/dev/patri9ck/a2ln/settings/SettingsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private void sendNotificationDirectly() {
256256

257257
CompletableFuture.supplyAsync(() -> notificationSender.sendParsedNotification(new ParsedNotification(getString(R.string.app_name),
258258
getString(R.string.notification_title),
259-
getString(R.string.notification_text)))).thenAccept(keptLog -> requireActivity().runOnUiThread(() -> succeed(keptLog.format())));
259+
getString(R.string.notification_text), requireContext().getPackageName()))).thenAccept(keptLog -> requireActivity().runOnUiThread(() -> succeed(keptLog.format())));
260260
});
261261
}
262262

0 commit comments

Comments
 (0)