2
3

More than 1 year has passed since last update.

AndroidTVに任意の通知(Notifications)を表示する

Last updated at Posted at 2021-12-29

背景

TVで録画番組を再生していると緊急地震速報を受け取れないのが気になっていた。
(我が家の緊急地震速報受信システムについては別途記載)
その前段として、TVに任意のメッセージを表示させる方法を知りたかった。
調べたものの、Androidスマホの通知をAndroidTVに表示させるAppは存在するものの、任意のメッセージを表示させるAppは存在しなかった。
AndroidTV自体にもそのようなAPIは存在しなかった。

必要なもの

  • Android TV ( Sony Bravia X8000Hを利用)
  • Notifications for Android TV(Android TVに通知を表示させるApp)
  • 任意のHTTPリクエストを発行できる端末

準備

  • 手持ちのAndroid端末にNotifications for Android TV をインストール
  • TVにNotifications for Android TVをインストール

調査

まずはAndroid端末でからプッシュされた通知がAndroidTVで表示されることを確認しました。
次にAndroid端末でpcapを取得し、どのような通信をすることでNotificationを表示させているのかを確認。

Notifications for Android TV をインストールすることで、AndroidTVはポート7676でHTTPサーバを立ち上げることが判明。
HTTPリクエスト内のPOSTパラメータに表示文字のサイズ、位置、メッセージ等を含めることで任意のNotificationを表示させることが可能だった。

サンプルリクエスト

パラメータ名 パラメータ値
type 0
title 表示させたいタイトル
msg 表示させたいメッセージ
duration 表示させたい時間(s)
fontsize フォントサイズ:3
position 表示位置:4
width 横幅:4
bkgcolor 背景色:#F44336
(任意の色が設定可能なわけではない)
transparency ?:1
offset 位置?:0
offsety 位置?:0
app ?:Notifications
force ?:true
file1 アイコンの画像ファイル:pngでOK
#Sample.py
import requests

# Parameters
files = {
    'type': (None, '0'),
    'title': (None, 'TITLE'),
    'msg': (None, 'MESSAGE'),
    'duration': (None, '1'),
    'fontsize': (None, '3'),
    'position': (None, '4'),
    'width': (None, '4'),
    'bkgcolor': (None, '#F44336'),
    'transparency': (None, '1'),
    'offset': (None, '0'),
    'offsety': (None, '0'),
    'app': (None, 'Notifications'),
    'force': (None, 'true'),
    'file1': ('icon.png', '1',  'application/octet-stream'),
 }
response = requests.post('http://***.***.***.***:7676/', files=files,timeout=3.5)

結果

ちゃんと表示された。(キャプチャは別途貼る)

その他

緊急地震速報は (1) SinalNowX -> (2) SynSNE -> (3) Zabbix -> (4) Pythonスクリプト -> (5) AndroidTV and (6) NW型Patlite で表示&音声案内をしています。
今回記載したのは(4)~(5)へのつなぎの箇所でした。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3