I'm playing around with notifications on Android/Google TV clients and I'm 99% sure I've got code that works.
Code a couple of different ways
Windows Command Line
curl http://10.255.1.168:57000/api/notify -H "Content-Type: application/json" -X POST -d "{'title': 'Alert', 'message': 'Dad is home'}"
Python
...
json_data = { "title": local_channels_client_notify_title_input, "message": local_channels_client_notify_message_input }
response = post_url(url, json_data, retries, delay)
...
def post_url(url, json_data, retries, delay):
timeout_duration = 120
for attempt in range(retries):
try:
if json_data:
response = requests.post(url, headers=url_headers, json=json_data, timeout=timeout_duration)
else:
response = requests.post(url, headers=url_headers, timeout=timeout_duration)
if response.status_code == 200:
return response
else:
raise Exception(f"HTTP Status Code {response.status_code}")
except Exception as e:
if attempt < retries - 1:
print(f"\n{current_time()} WARNING: For '{url}', encountered an error ({e}). Retrying in {delay} seconds...")
time.sleep(delay)
else:
notification_add(f"\n{current_time()} ERROR: For '{url}', after {retries} attempts, could not resolve error ({e}). Skipping...")
No matter the method, I get positive responses...
From curl
{"Success":"Notification sent."}
From Client Log
02-17 19:26:56.072 26111 8248 I ApiServer: REQUEST: POST /api/notify
02-17 19:26:56.074 26111 8248 I ApiServer: notify payload: {"title":"Test Title","message":"This is a test message with some words"}
However, despite that, I never seem to get a notification to pop up. As such, I'm quite sure the problem is something I've set on the client side in some type of option or blocker, but I'm not sure what. Anyone have any idea what I can look into? As far as I can tell, I've allowed the Channels app to give notifications, so I feel this has to be something system-level or something I'm just not thinking of...