Android Question Notification and SoundPool

fishwolf

Well-Known Member
Licensed User
Longtime User
I have a service that create a notification and play a custom sound.

work fine, but i enable the notification clear, doesn't play the sound.

i change only
Notif.OnGoingEvent = True -> False

Thanks

B4X:
Sub Process_Globals
Dim Notif As Notification
Dim NotifSound As SoundPool
Dim NotifID As Int
End Sub

Sub Service_Create

   Notif.Initialize
   Notif.Icon = "notification"
   Notif.Sound = False
   Notif.Vibrate = False
   Notif.Light = False
   ' Notif.OnGoingEvent = True
   Notif.OnGoingEvent = False
   Notif.AutoCancel = False
   'Notif.Number = Counter
 
   NotifSound.Initialize(2)
   NotifID = NotifSound.Load(File.DirAssets, "notification.ogg")
 
End Sub

Sub Service_Start (StartingIntent As Intent)
       Notif.SetInfo2(Title, Body, "IDNews", Calendar)
       Notif.Notify(1)  
   
        NotifSound.Play(NotifID, 1, 1, 1, 0, 1)
end sub
 

fishwolf

Well-Known Member
Licensed User
Longtime User
work fine with a little sleep

WHY ?

B4X:
Sub Service_Start (StartingIntent As Intent)

   Notif.SetInfo2("AAAA", "BBBB", "CCC", View1)
  Notif.Notify(1)  
   
   For i=0 To 10000
           Log ("I=" & i)
         Next
   
  NotifSound.Play(NotifID, 1, 1, 1, 1, 1)
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Are you doing this to play a custom sound?

If yes, maybe look at the Notification Builder library and use the customSound method

NOTE: for notification builder the sound file must first be copied from assets to another location.
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
Are you doing this to play a custom sound?

If yes, maybe look at the Notification Builder library and use the customSound method

NOTE: for notification builder the sound file must first be copied from assets to another location.

yes, a custom sound

i don't use Notification Builder library because i need run app on < 4.0 android version
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
It should work fine on < 4.0. Quite simply, only the features that are supported by the version of android in use will work. the others simply do not (no errors)

I believe setting the sound to play has been available since API 1 so will work on all versions
 
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
define var
Notif and notifsoud (and others)
in other module.
maybe the var are garbaged by system.
 
Upvote 0
Top