Android Question Notifications B4A Version 8.0

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hello,

I have a problem with notifications:

Dim NewNotification As Notification
NewNotification.Initialize2(NewNotification.IMPORTANCE_HIGH)
NewNotification.Light= Led
NewNotification.Sound= Sound
NewNotification.Vibrate= Vibrate
NewNotification.Icon= Icon
NewNotification.SetInfo(NameVersion, Message, "Main")
NewNotification.Notify(NotificationID)
Service.StartForeground(NotificationID, NewNotification)

when Led is set to true, the led on the Phone is not working.

I've tested with this:
- Samsung S4
- Samsung S7

when i test it with Nexus running Copperhead then the Led is working but is seems to be the only way to switch off the led is canceling the notification when you select the notification.

The Led used to work using NotificationBuilder, versionsafe notification, but I attempt to use the standard provided libraries.

Is something wrong with the new notification object or am I doing something wrong?
 

fransvlaarhoven

Active Member
Licensed User
Longtime User
Yes, I'm testing this with screen off.

I verified again and I'm sure, the led is not functional.

This is the code I'm using:

B4X:
Private Sub CreateNotification(Message As String, Icon As String, TargetActivity As Object, Sound As Boolean, Vibrate As Boolean, Led As Boolean)
 If (Message <> "") Or (Icon <> "") Then
  Dim NewNotification As Notification
  NewNotification.Initialize2(NewNotification.IMPORTANCE_HIGH)
  NewNotification.Sound= Sound
  NewNotification.Vibrate= Vibrate
  NewNotification.Icon= Icon
  If Led= True Then
   Dim r As Reflector 'Reflection library
   r.Target = NewNotification 'notification object
   r.SetField("flags", Bit.Or(r.GetField("flags"), 1), "java.lang.int")
  Else
   NewNotification.Light= Led
  End If
  NewNotification.SetInfo(NameVersion, Message, TargetActivity)
  NewNotification.Notify(NotificationID)
  Service.StartForeground(NotificationID, NewNotification)
 End If
End Sub
 
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hello,

I did some further testing with the new notification object adding:

If Led= True Then
Vibrate= True
End If

- it works for Samsung S4 running Android 5.0.1
- it works for Nexus 5X running Copperhead Android version 8.1.0
- it also works for Samsung S7 running Android version 7.0


=> It might be that the problem with the led is not related to the new notification object but is related to Samsung S7 running Android version 7.0

=> I also noticed that for Nexus 5X running Copperhead Android version 8.1.0, one has to select the notification in order to switch off the led.
It might be that this problem is related to Copperhead and not to the notification object. I have to do some further testing using Samsung S8



I'm using the following code:

B4X:
Private Sub CreateNotification(Message As String, Icon As String, TargetActivity As Object, Sound As Boolean, Vibrate As Boolean, Led As Boolean) As Notification
 If (Message <> "") Or (Icon <> "") Then
  If Led= True Then
   Vibrate= True
  End If
  Dim Title As String= NameVersion
  Dim NewNotification As Notification
  NewNotification.Initialize2(NewNotification.IMPORTANCE_HIGH)
  NewNotification.Sound= Sound
  NewNotification.Vibrate= Vibrate
  NewNotification.Icon= Icon
  If Led= True Then
   Dim r As Reflector 'Reflection library
   r.Target = NewNotification 'notification object
   r.SetField("flags", Bit.Or(r.GetField("flags"), 1), "java.lang.int")
  Else
   NewNotification.Light= Led
  End If
  NewNotification.SetInfo(Title, Message, TargetActivity)
  NewNotification.Notify(NotificationID)
  Service.StartForeground(NotificationID, NewNotification)
  Return NewNotification
 Else
  Dim NewNotification As Notification
  NewNotification.Initialize2(NewNotification.IMPORTANCE_HIGH)
  NewNotification.Cancel(NotificationID)
  Return NewNotification
 End If
End Sub
 
Upvote 0
Top