Android Question Notification in service problem

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I have been to have a notification icon in my service.
I tried both the default Notification as well as the CustomNotification (http://www.b4x.com/android/forum/threads/custom-notification-library-barx.16950/)

The second works on an emulator but crashes on my Galaxy S3.

This is an example of the default notification

B4X:
#Region  Service Attributes
  #StartAtBoot: True
#End Region
 
Sub Process_Globals
  Dim ntf As Notification
End Sub
 
Sub Service_Create
  ntf.Initialize
  ntf.Icon = "icon"
  ntf.AutoCancel = True
  ntf.Vibrate = True
  ntf.Light = True
  ntf.Sound = True
  ntf.SetInfo ("foo", "foo", Main)
End Sub
 
 
Sub Service_Start (StartingIntent As Intent)
  Service.StartForeground(1, ntf)
End Sub
 
 
Sub pc_CountersRead (p1Counter As Int, p2Counter As Int)
  ntf.Number = 11 'just demo
  ntf.Notify(1)
End Sub

On my Galaxy S3 I get following exception when the Service is started

** Service (svcmain) Create **
** Service (svcmain) Create **
** Service (svcmain) Start **
** Service (svcmain) Start **
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=b4a.example id=1 notification=Notification(pri=0 contentView=null vibrate=default sound=default defaults=0xffffffff flags=0x50 kind=[null]) tickerText=null contactCharSeq=null when=1377029474251 threadId=0
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=b4a.example id=1 notification=Notification(pri=0 contentView=null vibrate=default sound=default defaults=0xffffffff flags=0x50 kind=[null]) tickerText=null contactCharSeq=null when=1377029474251 threadId=0
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)


Thank you !!
 

wl

Well-Known Member
Licensed User
Longtime User
I got exactly the same problem (same Exception) when I'm using the CustomNotification (I copied the res folder and made it readonly).
I just can't seem to have the notification in a service working on my S3 (Android 4.1.2). I used Android.jar version 17 to build

EDIT: It seems I do NOT receive the exception when I omit the setIcon method call ??

B4X:
#Region  Service Attributes
    '#StartAtBoot: True
    '#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
 
Sub Process_Globals
End Sub
 
Sub Service_Create
End Sub
 
 
Sub Service_Start (StartingIntent As Intent)
End Sub
 
Sub Service_Destroy
End Sub
 
Sub SomeEvent ()
    Dim cn As CustomNotification
      cn.Initialize(1)
    cn.Number = 1
    cn.setIcon("icon")
    cn.TickerText = "Default Notification Sample"
    cn.AutoCancel = True
    cn.SetTextColor("title", Colors.Red)
    cn.SetTextColor("text", Colors.Blue)
    cn.SetText("title", "Default Notification Title")
    cn.SetText("text", "Second text line")
    cn.SetTextSize("title", 16)
    cn.Notify(1)
End Sub
 
Last edited:
Upvote 0
Top