Closed aykutuludag closed 9 months ago
Suggestion: I found some part in your Android code.
if (fullScreen) {
notificationBuilder.setFullScreenIntent(notificationPendingIntent, true)
}
I guess this part opens notification automatically but in best scenario we give this choice to user either open notification or dismiss it. I believe that this part should be removed or should be optional. (ex: bool autoOpenNotification: true/false). Have a nice weekend.
Note: Actually I have no problem with opening notification automatically. Real problem is, it is skipping splash screen and related codes and directly jump to application. I don't know why. But in any case, making it optional is best choice for everyone. If we found the problem and fix it, I will probably use with autoOpenNotification true.
Suggestion: I changed your code a little bit for myself to show notification icon:
val bm: Bitmap = BitmapFactory.decodeResource(context.getResources(), iconResId)
notificationBuilder
.setSmallIcon(iconResId)
.setLargeIcon(bm)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setAutoCancel(true)
.setContentIntent(notificationPendingIntent)
.setSound(null)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
I added .setLargeIcon(bm), in this way users can see application icon inside notification. I tested it and released it works perfectly.
Hi @aykutuludag
About the full screen notification, there's a parameter for this: androidFullScreenIntent
, true by default. Have you tried to disable it ?
About the notification large icon, thanks for sharing your code. I'll add it to the next release !
Hi @aykutuludag
About the full screen notification, there's a parameter for this:
androidFullScreenIntent
, true by default. Have you tried to disable it ?
You are right! My mistake I couldn't see that variable I don't understand how. No further comment for that, I set it up from dart side. I changed as following for further reference:
Future<void> createAlarm(int alarmId, DateTime dateTime, String title, String body) async {
final alarmSettings = AlarmSettings(
id: alarmId,
dateTime: dateTime,
assetAudioPath: 'assets/notification.mp3',
loopAudio: false,
vibrate: true,
volume: 1,
notificationTitle: title,
notificationBody: body,
enableNotificationOnKill: false,
androidFullScreenIntent: false
);
await Alarm.set(alarmSettings: alarmSettings);
}
Also It's skipping splash screen when automatic open is active. I don't know why it is just skipping splash screen and related codes (The codes in the main function before calling runApp(MyApp())) and jump to Home Screen. But if user clicked notification by himself, it works normally except one thing I wrote below. I am using https://pub.dev/packages/flutter_native_splash plugin to create splash screens. Expectation is either clicking notification by himself or open notification automatically, it should open splash screen first, then Home Screen.
Also Android >= 12, when user clicked the notification he sees empty splash but if it click the launcher icon, he see splash screen with icon (normal view). It's probably not related with your plugin but related with Android. Your pendingIntent may require modifications. Take a look: https://stackoverflow.com/questions/73919563/android-12-splash-screen-icon-not-showing-from-notification
So far I found those bugs in Android, my friend. I wrote my finding on iOS to iOS issue. Have a nice weekend.
Fatal Exception: java.lang.RuntimeException: Unable to start service com.gdelataillade.alarm.alarm.AlarmService@c777b30 with Intent { cmp=com.appname/com.gdelataillade.alarm.alarm.AlarmService (has extras) }: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.appname/com.gdelataillade.alarm.alarm.AlarmService at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4963) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at android.app.ActivityThread.main(ActivityThread.java:8410) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Other than this error, I couldn't detect any error so far on Android. Best regards.
Note: My suspect that this is only occurring when app is open alarm is triggered at that moment. Service couldn't start foreground, I guess.
Also about this, it says android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false My guess is that application is foreground and you can't start backgroundService while app is open. You may add some controls that if it is background startBackgroundService. If it is not, you just need to start your codes without service. Kind regards
This error is only occurring Android >= 12.
Additional readings: https://stackoverflow.com/a/70666991/4606368
Hi @aykutuludag
I just release version 3.0.6
with changelog:
Let me know if it works for you. I will now focus on the new bugs you shared in this thread.
Have a great week !
Hi @aykutuludag
About notification setOngoing
, which is false by default. I read that for foreground services it was mandatory to specify .setOngoing(true)
. This requirement is part of Android's approach to ensure user awareness of ongoing processes that could affect the device's performance or battery life. By the way, this could be the reason of your ForegroundServiceStartNotAllowedException
.
I'm setting setAutoCancel(true)
though. This way, notification will be automatically dismissed when tapped.
Can you confirm something we already discussed: you don't want the notification to be auto-dismissed, right ? Even when loopAudio was false and alarm audio & vibrations ended.
id's approach to ensure user awareness of ongoin
Exacly, this is the expected behavior on notification's on mobile app. I will upgrade plugin on my project and released new version asap. Have a nice day.
For setOngoing you are probably right. I will share bug reports if any error comes from v3.0.6
Fatal Exception: java.lang.RuntimeException: Unable to start service com.gdelataillade.alarm.alarm.AlarmService@c777b30 with Intent { cmp=com.appname/com.gdelataillade.alarm.alarm.AlarmService (has extras) }: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service com.appname/com.gdelataillade.alarm.alarm.AlarmService at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4963) at android.app.ActivityThread.-$$Nest$mhandleServiceArgs() at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2288) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at android.app.ActivityThread.main(ActivityThread.java:8410) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Other than this error, I couldn't detect any error so far on Android. Best regards. Note: My suspect that this is only occurring when app is open alarm is triggered at that moment. Service couldn't start foreground, I guess.
Also about this, it says android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false My guess is that application is foreground and you can't start backgroundService while app is open. You may add some controls that if it is background startBackgroundService. If it is not, you just need to start your codes without service. Kind regards
This error is only occurring Android >= 12.
Additional readings: https://stackoverflow.com/a/70666991/4606368
https://github.com/gdelataillade/alarm/issues/142 and https://github.com/gdelataillade/alarm/issues/141 is related with this error.
Hi @aykutuludag
I just released version 3.0.7
with some native android fixes. Hope it will fix your issues !
Huge thanks for your effort. I'm applying v3.0.7 and sending new release. I will share if any bug encounters. Best regards.
Other than this error, I couldn't detect any error so far on Android. Best regards.
Note: My suspect that this is only occurring when app is open alarm is triggered at that moment. Service couldn't start foreground, I guess.