Skip to content

Commit

Permalink
Fix android notification icon
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Apr 19, 2024
1 parent 18b0f3b commit aebf0a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.gdelataillade.alarm.services

import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.provider.Settings
import android.os.Build
import android.os.IBinder
import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import io.flutter.Log

class NotificationOnKillService: Service() {
class NotificationOnKillService : Service() {
private lateinit var title: String
private lateinit var body: String
private val NOTIFICATION_ID = 88888
Expand All @@ -33,8 +34,9 @@ class NotificationOnKillService: Service() {
val notificationIntent = packageManager.getLaunchIntentForPackage(packageName)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)

val appIconResId = packageManager.getApplicationInfo(packageName, 0).icon
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_notification_overlay)
.setSmallIcon(appIconResId)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(false)
Expand All @@ -46,10 +48,9 @@ class NotificationOnKillService: Service() {
val descriptionText = "If an alarm was set and the app is killed, a notification will show to warn the user the alarm could not ring as long as the app is killed"
val importance = NotificationManager.IMPORTANCE_HIGH
val channel = NotificationChannel(CHANNEL_ID, name, importance).apply {
body = descriptionText
description = descriptionText
}

// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
Expand All @@ -63,4 +64,4 @@ class NotificationOnKillService: Service() {
override fun onBind(intent: Intent?): IBinder? {
return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class NotificationHandler(private val context: Context) {
}

fun buildNotification(title: String, body: String, fullScreen: Boolean, pendingIntent: PendingIntent): Notification {
val iconResId = context.resources.getIdentifier("ic_launcher", "mipmap", context.packageName)
val largeIcon = BitmapFactory.decodeResource(context.resources, iconResId)
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
val appIconResId = context.packageManager.getApplicationInfo(context.packageName, 0).icon
val largeIcon = BitmapFactory.decodeResource(context.resources, appIconResId)
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName) ?: Intent()
val notificationPendingIntent = PendingIntent.getActivity(
context,
0,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
Expand All @@ -55,7 +55,7 @@ class NotificationHandler(private val context: Context) {
}

notificationBuilder
.setSmallIcon(iconResId)
.setSmallIcon(appIconResId)
.setLargeIcon(largeIcon)
.setContentTitle(title)
.setContentText(body)
Expand Down
4 changes: 3 additions & 1 deletion lib/src/android_alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class AndroidAlarm {
}
}

alarmPrint('Alarm with id ${settings.id} scheduled');
alarmPrint(
'''Alarm with id ${settings.id} scheduled at ${settings.dateTime}''',
);

return true;
}
Expand Down

0 comments on commit aebf0a2

Please sign in to comment.