Android Question Notifications seem to work differently in Oreo

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

All of my apps are using this coding to display a notification that lets the user know the app is running in the background. The coding was working correctly on my test phone running Android 7.

In the Starter module:

In the Process_Globals:

B4X:
    Private nNotify As Notification

In the Service_Create:

B4X:
    InitializeObjects

    nNotify.SetInfo("My app name goes here", "Running in the background...", "")
        
    Service.AutomaticForegroundNotification = nNotify
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
    wakeState.PartialLock

In the InitializeObjects:

B4X:
    nNotify.Initialize
    nNotify.Icon = "icon"
    nNotify.Sound = False
    nNotify.Light = False
    nNotify.Vibrate = False

    tmrTimer.Initialize("Timer", 1000) ' Every second.

    strShared = rp.GetSafeDirDefaultExternal("Settings")
    kvs.Initialize(strShared, "Settings")

After upgraded to Oreo, all I see "My app name goes here" for both the title and the body in the notification area and the phones default notification sound is heard even though I told it not to play the sound with nNotify.Sound = False

Can you let me know what code changes I need to make so it will work in both Oreo and older versions as well?

Thanks.
 

Peter Simpson

Expert
Licensed User
Longtime User
Are you using B4A 8.3?
The built-in notifications in 8.3 works perfectly fine with Oreo, I use it on my phone and watch every single with no issues whatsoever.

If yes to 8.3, just use the built in notifications...
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Thanks for the replies.

I'm using version 8.30

The issue is happening to all of my apps that my customers are using.

Is the coding correct for Oreo? It worked on Android 7.0

Please show the coding changes I need to make.

An example app would also help in case I need to use the manifest editor to make changes to the manifest.

Thanks.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
You should read that tutorial. There is no point in us posting the same information here.
Hi Erel,

The tutorial tells me, I can use
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
to force the service to run in the foreground which is one of the lines of coding I'm using but it doesn't look like that's working because the title and body that's displayed is the same. Should I move the
nNotify.SetInfo("My app name goes here", "Running in the background...", "")
line to another location in Service_Create or another sub routine?

Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The notification with the same title and body is the default automatic foreground notification. It has nothing to do with any other notification.

You can set a different notification to be the automatic foreground notification by setting Service.AutomaticForegroundNotification (in Service_Create). Or you can stop automatic foreground mode and handle the foreground state yourself.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
The notification with the same title and body is the default automatic foreground notification. It has nothing to do with any other notification.

You can set a different notification to be the automatic foreground notification by setting Service.AutomaticForegroundNotification (in Service_Create). Or you can stop automatic foreground mode and handle the foreground state yourself.

Hi Erel,

I need to keep foreground mode going. The coding from the app set up the notification is here which is what I was using before Oreo:

B4X:
    nNotify.Icon = "icon"
    nNotify.Sound = False
    nNotify.Light = False
    nNotify.Vibrate = False

The tutorial also states:

Another new property is Service.AutomaticForegroundNotification. This allows you to change the notification that appears in automatic foreground mode.

It never actually showed an example with coding so I assumed I was to use:

B4X:
Service.AutomaticForegroundNotification = nNotify

Since it compiled and did not crash my app I was good to go and published the app. When my customers started to upgrade to Oreo they had either crashes or the default system notification showing up.

It seems that using Service.AutomaticForegroundNotification the way I was using it is not correct for Oreo.

It would be greatly appreciated if I can see the coding I need to use to build the notification to work with Oreo and Service.AutomaticForegroundNotification.

Thanks.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
The very short code you posted looks correct. You need to test it on an Android 8 device.

Hi Erel,

My development phone is running on Oreo. This problem is happening on all of my apps and I have done quite a lot of them. It started to happen when my customers upgraded to Oreo. On their Asus phones they get crashes and on Samsung phones they get the system notification instead of the custom one you see in the code sample.

Google should have done more testing before releasing Oreo.

Is there a work-around I can implement so there are no crashes and be able to display the custom notification I was using when the customers had Android 7.0 ?
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Erel,
I'm not familiar with any issue related to notifications.

We cannot say anything as you even haven't posted the error message.

Hi Erel,

They get the standard Android message that "Unfortunally appname is not working".

If you can post a real small app based on my coding that sets a custom notification in the starter module that will allow me to compare something that's working for you guys to what I have.

Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you can post a real small app based on my coding that sets a custom notification in the starter module that will allow me to compare something that's working for you guys to what I have.
It is not possible. Sorry.

They get the standard Android message that "Unfortunally appname is not working".
You need to reproduce it yourself and check the logs. You will see the error message there.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
It is not possible. Sorry.


You need to reproduce it yourself and check the logs. You will see the error message there.

Hi Erel,

Since I have a Samsung phone, I don't get the error message but do get the default notification instead of the custom one.
 
Upvote 0
Top