Android Question [SOLVED] Placing a widget causes notification title and body to be duplicated.

Discussion in 'Android Questions' started by rleiman, Dec 16, 2018.

  1. rleiman

    rleiman Well-Known Member Licensed User

    Hi Everyone,

    I'm having a problem where placing the app widget on the screen causes the notification title and body to be duplicated when the user pulls down the notifications drawer.

    Here's the code that places the title and body of the notification which is in the starter service.

    Code:
    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.

        SetupDefaultSettingsDatabase
        InitializeObjects
        
        nNotify.Initialize2(nNotify.IMPORTANCE_LOW)
        nNotify.Icon = 
    "icon"
        nNotify.SetInfo(
    "My app name is here",  "This is the body text...""")
        
    Service.AutomaticForegroundNotification = nNotify

        
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
        wakeState.PartialLock

        StartTheTimer
    End Sub
    The notification works perfectly only if the user doesn't put the widget on the screen. As soon as the user does that, the body and title are duplicated when the user pulls down the notifications drawer.

    I can live with this but it would be nicer if the app shows the notification in a consistent way.

    Please forgive me if this thread sounds similar to another one I posted earlier which I closed as solved.

    Thanks
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Why are you setting automatic foreground mode to 'always'?

    You should call Service.StopAutomaticForeground after you are done updating the widget.

    Must read: Automatic Foreground Mode
     
  3. rleiman

    rleiman Well-Known Member Licensed User

    Hi Erel,

    I will try that later today. Thanks.

    I'm setting it to "Always" so Android will not put the app to sleep.
     
  4. rleiman

    rleiman Well-Known Member Licensed User

    Hi Erel,

    I tried but still get the duplicates when the widget is placed on the screen.

    Code:
    public Sub UpdateWidgetIcon

        
    ' Determine which image to display from the file name.
        '-----------------------------------------------------
        rv.SetImage("ImageViewWidgetIcon"LoadBitmap(File.DirAssets, kvs.Get("WidgetIconFileName")))
        rv.UpdateWidget
        
    Service.StopAutomaticForeground
    End Sub
     
  5. rleiman

    rleiman Well-Known Member Licensed User

    I got it working by changing the coding to this.

    Code:
    public Sub UpdateWidgetIcon

        
    ' Determine which image to display from the file name.
        '-----------------------------------------------------
        rv.SetImage("ImageViewWidgetIcon"LoadBitmap(File.DirAssets, kvs.Get("WidgetIconFileName")))
        rv.UpdateWidget
        nNotify.Initialize2(nNotify.IMPORTANCE_LOW)
        nNotify.Icon = 
    "icon"
        nNotify.SetInfo(
    "My app name is here",  "This is the body text...""")
        
    Service.AutomaticForegroundNotification = nNotify
        
    Service.StopAutomaticForeground
    End Sub
     
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