Android Question Notification Problem When App Is Closed Android > 8,9 [image]

Ertan

Active Member
Licensed User
Hello there,

I am using firebase to send notification. I use the NB6 library to customize notifications.

A few problems arise when android 8,9> from a non-SSL site.

I use the NB6 library for picture notification.

I keep the image on my remote server and I provide the url of the image in the "image" section and download it.

On my Android 6 phone, I can get picture notifications when the application is closed without any problem, but as of Android 8.9, I cannot receive the notification because the application cannot download the picture when it is closed.

Is this because my site doesn't have SSL? Or what else?

By adding this code in the Manifest editor, I was able to extract data from sites without https with android 8,9. But when the application is closed, the picture etc. I can not download.
B4X:
SetApplicationAttribute(android:usesCleartextTraffic, "true")

B4X:
Dim ringtone As String="shotgun.mp3"
        Dim rp As RuntimePermissions
        Dim folder As String = rp.GetSafeDirDefaultExternal("shared")
        Dim FileName As String = ringtone
        File.Copy(File.DirAssets, FileName, folder, FileName)
        Dim n As NB6
        n.Initialize("Channel1", Application.LabelName, "HIGH")
        n.SmallIcon(LoadBitmapResize(File.DirAssets, "arac2.png", 32dip, 32dip, True))
        n.SetDefaults(False, True, True)
        n.CustomSound(CreateFileProviderUri(folder, FileName))
    
        Dim b As Bitmap
        Dim j As HttpJob
        j.Initialize("", Me)
        j.Download(Message.GetData.Get("image"))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            b = j.GetBitmap
        End If
        j.Release
    
        n.BigPictureStyle(b.Resize(256dip, 256dip, True), _
        b, Message.GetData.Get("title"), Message.GetData.Get("body"))
        n.Color(0xFF00AEFF)
        n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), "tag", Me).Notify(7)
 

Ertan

Active Member
Licensed User
Add some log messages to better understand what happens.
Note that your app will crash if it failed to download the image.
B4X:
Logger connected to: 2b58637238027ece
--------- beginning of crash
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzn@e2a2e4f
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
dwoiBdP2ThKFdbxm-lOsF_:APA91bGjQpvmSsCdT8k9CaokDcTsf9UTbDxskcw72UWXdzJza6yG7FPXztgH8IMQJbaSMT7hjr1TkX2EUoMkl2yCB0G1NhzJP0V-7sVXKYTlmWKGy3N_uTpD1yeU9dYgykQs5CfM6xv9
** Activity (main) Pause, UserClosed = true **
** Activity (anasayfa_layout) Create, isFirst = true **
** Activity (anasayfa_layout) Resume **
** Activity (anasayfa_layout) Pause, UserClosed = false **
** Receiver (firebasemessaging) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **
** Service (firebasemessaging) Create **
** Service (firebasemessaging) Start **
Service started in foreground mode.
onAuthStateChanged: com.google.firebase.auth.internal.zzn@d2936b2
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "b4x-4c17.kxcdn.com": No address associated with hostname, Response:
firebasemessaging$ResumableSub_fm_MessageArrivedresume (java line: 286)
java.lang.RuntimeException: Object should first be initialized (Bitmap).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize(CanvasWrapper.java:558)
    at hds.fiestam.firebasemessaging$ResumableSub_fm_MessageArrived.resume(firebasemessaging.java:286)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8167)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

**Picture notification comes when the application is open. However, when the application is closed, there is no notification and the application crashes because it cannot download the picture.

There is no problem with my Android 6 device but android 8.9 and above is problematic. Where am i missing?

Thank you.
 
Last edited:
Upvote 0

Ertan

Active Member
Licensed User
As I wrote, your code is wrong. It tries to access the bitmap even if download failed. First step is to fix it.

Which image are you downloading? Why from B4X?
I got a picture from the B4X for just a trial. The problem is how do we get it to access the picture? The application is unable to access the picture and gives an error when it is closed. How can we access the picture?
Can't access the picture in the background, what's the point of accessing the picture only when the app is open?
 
Upvote 0

Ertan

Active Member
Licensed User
I explained the details of the problem in #1.
On my Android 6 phone, I can get picture notifications when the application is closed without any problem, but as of Android 8.9, I cannot receive the notification because the application cannot download the picture when it is closed.
Is this because my site doesn't have SSL? Or what else?
 
Upvote 0

Ertan

Active Member
Licensed User
Notification comes when the application is open.
log while the application is open;

Notification and Log When the Application is Open:
Logger connected to: 2b58637238027ece
--------- beginning of crash
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzn@54e9980
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
dwoiBdP2ThKFdbxm-lOsF_:APA91bGjQpvmSsCdT8k9CaokDcTsf9UTbDxskcw72UWXdzJza6yG7FPXztgH8IMQJbaSMT7hjr1TkX2EUoMkl2yCB0G1NhzJP0V-7sVXKYTlmWKGy3N_uTpD1yeU9dYgykQs5CfM6xv9
** Activity (main) Pause, UserClosed = true **
** Activity (anasayfa_layout) Create, isFirst = true **
** Activity (anasayfa_layout) Resume **
** Receiver (firebasemessaging) OnReceive **
** Service (firebasemessaging) Start **

This issue is only on Android 10 and the app won't download when it's closed.

By adding this code in the Manifest editor, I was able to extract data from sites without https with android 8,9. But when the application is closed, the picture etc. I can not download.
B4X:
SetApplicationAttribute(android:usesCleartextTraffic, "true")

Cannot access the website in any way. What is the purpose of using picture notification because it cannot access?
Do I need to add something else to the manifest file? Need permission?
 
Upvote 0

By-Cod3rs

Member
Licensed User
I recommend you to carefully read my answers. Everything that you wrote is wrong.

dear erel, we are working with ertan.
1-Forget what is written.
2-The application works on Android 9 and below, there is no problem.
3-However, if the application is OFF in Android 10, an error occurs in the IMAGE notification.
4-If the Android 10 App is open, No Problem.
Do you have a suggestion?
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
On my Android 6 phone, I can get picture notifications when the application is closed without any problem, but as of Android 8.9, I cannot receive the notification because the application cannot download the picture when it is closed.
I was have a similar case of your problem, It was related to recent versions of android os "new android policies", they kill any background service/process, so when your app in background, your service/process mostly stopped. But in old versions of android os this case not happen.
 
Upvote 0

Ertan

Active Member
Licensed User
I was have a similar case of your problem, It was related to recent versions of android os "new android policies", they kill any background service/process, so when your app in background, your service/process mostly stopped. But in old versions of android os this case not happen.
Yes, we understood that this is the problem, but I could not find the solution. Did you solve it?
 
Upvote 0

Ertan

Active Member
Licensed User
1. You should expect http requests to fail. Your app shouldn't crash because of it.
2. After you fix point #1 you should find out why it failed to download the image. Based on the logs you posted the device wasn't connected to the internet.
Dear Erel,

We received a link to an avatar in the forum for a reliable test. There was no "www" tag in the link.

www. The site turned out to be unsafe when we added it (non-SSL)

When we received a picture of another secure site, the notification was successfully sent to our phone while the application was closed.

Note: It is not possible to download from an unsafe site (non-SSL) in the background. (Android 9, Android 10)

It can be done on Android 6.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Yes, we understood that this is the problem, but I could not find the solution. Did you solve it?
Yes I solved it by workaround in which you tell android os your app is still active don't kill it.
How?
You already have a notification service module, just add another service module, then create two timers in both services and create a blank or whatever method inside each module, Then call each method from another service timer using callsubdelayed, so Android will keep your app alive in background forever.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You already have a notification service module, just add another service module, then create two timers in both services and create a blank or whatever method inside each module, Then call each method from another service timer using callsubdelayed, so Android will keep your app alive in background forever.
This will not do anything useful.

Note: It is not possible to download from an unsafe site (non-SSL) in the background.
This is also not correct.

I was have a similar case of your problem, It was related to recent versions of android os "new android policies", they kill any background service/process, so when your app in background, your service/process mostly stopped. But in old versions of android os this case not happen.
This has nothing to do with this thread as the app was started as a result of a push notification message. You can see that it started in the logs.

This is the only relevant information in this thread:
ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "b4x-4c17.kxcdn.com": No address associated with hostname, Response:
This error happens when there is no internet connection or there is some other network problem.

As this thread is too messed up with wrong information, I can no longer help here. Sorry.
 
Upvote 0
Top