Bug? Can't show notification large icon with B4A 8.3 in Android 4.4 device

Discussion in 'Bugs & wishlist' started by ppgirl, Jul 3, 2018.

  1. ppgirl

    ppgirl Member Licensed User

    I update this notification code @Erel for ~8.1 android . As I test , it works right for 8.1 and 6 device , but works incorrect in Android 4.4.2 (Samsung S3 SPH-L710). The small icon (status bar) is ok but large icon show a blank.

    The example code is very simple , create a new project and paste the code to Starter service :

    Other , B4A 8.3 and updated with B4A SDK manager , use android-27\android.jar

    Code:
    #Region  Service Attributes
        
    #StartAtBoot: False
        
    #ExcludeFromLibrary: True
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.
        Dim Notification1 As Notification
    End Sub

    Sub Service_Create
        
    'This is the program entry point.
        'This is a good place to load resources that are not specific to a single activity.
    End Sub


    Sub Service_TaskRemoved
        
    'This event will be raised when the user removes the app from the recent apps list.
    End Sub

    'Return true to allow the OS default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub


    Sub Service_Start (StartingIntent As Intent)
        
    Log("Start")
        
    If Not(Notification1.IsInitialized ) Then
        Notification1=CreateNotification(
    "Example","Tap here to set","icon",Main,False,False)
        
    End If
        
    Service.StartForeground(1, Notification1)
    End Sub

    Sub Service_Destroy
        
    Log("Destroy")
    End Sub

    Private Sub CreateNotification(Title As String, Content As String, Icon As String, TargetActivity As Object, _
        Sound 
    As Boolean, Vibrate As Boolean) As Notification
        
    Dim p As Phone
        
    If p.SdkVersion >= 21 Then
            
    Dim nb As NotificationBuilder
            nb.Initialize
            nb.DefaultSound = Sound
            nb.DefaultVibrate = Vibrate
            nb.ContentTitle = Title
            nb.ContentText = Content
            nb.setActivity(TargetActivity)
            nb.SmallIcon = Icon
            
    If p.SdkVersion >= 26 Then
                
    Dim ctxt As JavaObject
                ctxt.InitializeContext
                
    Dim manager As JavaObject
                manager.InitializeStatic(
    "android.app.NotificationManager")
                
    Dim Channel As JavaObject
                
    Dim importance As String
                
    If Sound Then importance = "IMPORTANCE_DEFAULT" Else importance = "IMPORTANCE_LOW"
                
    Dim ChannelVisibleName As String = Application.LabelName
                Channel.InitializeNewInstance(
    "android.app.NotificationChannel", _
                       
    Array("MyChannelId1", ChannelVisibleName, manager.GetField(importance)))
                manager = ctxt.RunMethod(
    "getSystemService"Array("notification"))
                manager.RunMethod(
    "createNotificationChannel"Array(Channel))
                
    Dim jo As JavaObject = nb
                jo.RunMethod(
    "setChannelId"Array("MyChannelId1"))
            
    End If
            
    Return  nb.GetNotification
        
    Else
            
    Dim n As Notification
            n.Initialize
            n.Sound = Sound
            n.Vibrate = Vibrate
            n.Icon = Icon
            n.SetInfo(Title, Content, TargetActivity)
            
    Return n
        
    End If
    End Sub
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    You don't need this code if you are using B4A v8+. The standard notification object will work with all versions.

    It will not set the large icon. You need to use NotificationBuilder for this.

    It is not a bug. For further discussion please start a new thread in the questions forum.
     
  3. ppgirl

    ppgirl Member Licensed User

    Thanks , The Erel's explanation clarify the puzzling problem.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice