Skip to content

Commit

Permalink
Add option to change status bar icon for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
yurimataev authored and xalexalex committed Apr 26, 2020
1 parent 02d46bf commit b261304
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/main/java/com/termux/api/NotificationAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.io.File;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -151,6 +152,23 @@ static Pair<NotificationCompat.Builder, String> buildNotification(final Context
notification.setWhen(System.currentTimeMillis());
notification.setShowWhen(true);

String SmallIcon = intent.getStringExtra("icon");

if (SmallIcon != null) {
final Class<?> clz = R.drawable.class;
final Field[] fields = clz.getDeclaredFields();
for (Field field : fields) {
String name = field.getName();
if (name.equals("ic_" + SmallIcon + "_black_24dp")) {
try {
notification.setSmallIcon(field.getInt(clz));
} catch (Exception e) {
break;
}
}
}
}

String ImagePath = intent.getStringExtra("image-path");

if (ImagePath != null) {
Expand All @@ -172,7 +190,9 @@ static Pair<NotificationCompat.Builder, String> buildNotification(final Context
String mediaNext = intent.getStringExtra("media-next");

if (mediaPrevious != null && mediaPause != null && mediaPlay != null && mediaNext != null) {
notification.setSmallIcon(android.R.drawable.ic_media_play);
if (SmallIcon == null) {
notification.setSmallIcon(android.R.drawable.ic_media_play);
}

PendingIntent previousIntent = createAction(context, mediaPrevious);
PendingIntent pauseIntent = createAction(context, mediaPause);
Expand Down

0 comments on commit b261304

Please sign in to comment.