Android Question AndroidTV push notification

ilan

Expert
Licensed User
Longtime User
hi

I just finished a project of an android app for android tv and mobile. the idea is that you have an app that is always running in the front on the android tv device and a mobile app (b4a/b4i) where you can make changes on what to display on the tv. to update the information on the tv I send a push from the mobile app and everything is updated on the tv.

I tested it on 2 TVs. 1 worked without any problem, but a cheaper one did not receive the push notification. and because the plan is to sell the whole package including the tv i prefer to go for cheaper models in the beginning.

i would like to let the user make the changes also far away from the tv so using another approach like Bluetooth is less an option for now. what i can do is put a timer in the app running on the tv and every x seconds a check is made to the mysql db using php that is running on a shared hosting.

so my question is this, what should be the period for the timer to check if there is an updated on the db? are 30 seconds ok?
do you have another recommendation on how to solve the problem?

i expect to have about 100-150 android tv devices so if i make a call every 30 seconds it means about 300.000 db calls per day. is that to much for shared hosting?

thanx, ilan
 

MichalK73

Active Member
Licensed User
Longtime User
I am very curious about your AndroidTV app as I wrote one myself.
As for your question.I would use the MQTT protocol.
I used such communication in several different systems whether it be python, androidtv etc
I think this will be a better solution for you than querying the server from time to time.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
I tested it on 2 TVs. 1 worked without any problem, but a cheaper one did not receive the push notification. and because the plan is to sell the whole package including the tv i prefer to go for cheaper models in the beginning.
Maybe issues with the "adapted" Google services. Are other apps receiving notifications? Try just data messages (throw the notification with NB6) and log if these arrive. Use high priority (when sending)

Check if your app is allowed to display messages (maybe there's a setting like in Android 10/11)

i expect to have about 100-150 android tv devices so if i make a call every 30 seconds it means about 300.000 db calls per day. is that to much for shared hosting?
That means about 4 per second (86400 secs/day) which isn't much. If you send to topics, it will be reduced further.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Code to send data messages with high priority:

B4X:
Dim m As Map = CreateMap("to": $"${Devtoken}"$)
   Dim data As Map = CreateMap("data": MyData)
    Dim pri As Map=CreateMap("priority":"high")
    m.Put("data", data)
    m.Put("priority", "high")
    m.Put("android", pri)
 
   Dim jg As JSONGenerator
   jg.Initialize(m)
   Log(jg.ToString)
   Log(jg.ToPrettyString(2))
   Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
   Job.GetRequest.SetContentType("application/json;charset=UTF-8")
   Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Code to send data messages with high priority:

B4X:
Dim m As Map = CreateMap("to": $"${Devtoken}"$)
   Dim data As Map = CreateMap("data": MyData)
    Dim pri As Map=CreateMap("priority":"high")
    m.Put("data", data)
    m.Put("priority", "high")
    m.Put("android", pri)
 
   Dim jg As JSONGenerator
   jg.Initialize(m)
   Log(jg.ToString)
   Log(jg.ToPrettyString(2))
   Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
   Job.GetRequest.SetContentType("application/json;charset=UTF-8")
   Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)

thank you @KMatle i will try it.

the weird thing is that one time the notification did arrive but then did not arrive anymore (on the cheap tv)
it seems like the fcm service is killed and is not getting the push notification but i am not sure.

if i run a tv emulator it works fine also on the more expensive tv it works fine. but on the cheap one only 1 time the notification arrives.
i will try the high-priority option. thanx :)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I am very curious about your AndroidTV app as I wrote one myself.
As for your question.I would use the MQTT protocol.
I used such communication in several different systems whether it be python, androidtv etc
I think this will be a better solution for you than querying the server from time to time.
this is the project: http://www.sagital.net/smarttv/

the idea is a smart lobby. if you want to inform the people in your building about something until today you would do it with paper notification. now you can do it in a more elegant way :)

 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Yup. Cheaper TV's may have a "non stable" Android system. I have a tablet and a TV-Box on which the WiFi disconnects all the time and doesn't reconnect anymore.
i agree.

this is the cheaper tv: https://www.tcl.com/hk/en/products/s65a/s65a-32.html

its around 240 euro

there is a XIAOMI tv that cost a little bit more and i think it is more stable. it cost around 310euro
maybe i will go with the xiaomi tv will see.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Good news guys. i am not sure if the code of @KMatle was the solution or other stuff i have changed in the code but it is now working perfect even on the cheap tv :)

thank you very much guys for your help !! 🙏 🙏 🙏
 
Upvote 0
Top