Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi phát hành Android 5.0, Android TV hỗ trợ Google Cast.
Tài liệu này mô tả những việc bạn cần làm để thiết lập và kiểm thử trên Android TV
khi phát triển ứng dụng Truyền. Ứng dụng Truyền hiện có của bạn chạy trên
Android TV mà không mất thêm công sức. Nếu bạn đang phát triển một ứng dụng Truyền
lần đầu tiên, hãy xem lại tài liệu về Google Cast
và phát triển ứng dụng Truyền của bạn để chạy trên thiết bị Chromecast trước tiên
phát triển và thử nghiệm với Android TV.
Thiết lập cho hoạt động phát triển
Thiết lập thiết bị Android TV:
Kết nối thiết bị Android TV với mạng cục bộ.
Đăng nhập vào Tài khoản Google của bạn.
Trên phần Settings (Cài đặt), trong hàng Device (Thiết bị), hãy chọn About (Giới thiệu).
Di chuyển xuống rồi nhấp vào Build (Tạo) vài lần cho đến khi một hộp thoại xuất hiện
xuất hiện cùng thông báo "Bạn hiện là nhà phát triển".
Nếu gỡ lỗi qua USB:
Lắp đặt cáp USB nhưng không kết nối đầu chính của cáp USB
đến máy tính của bạn.
Trong hàng Lựa chọn ưu tiên, hãy chọn Tuỳ chọn cho nhà phát triển rồi chọn
Gỡ lỗi qua USB rồi chọn Bật.
Quay lại màn hình chính. Bạn phải thực hiện thao tác này để áp dụng các chế độ cài đặt mà bạn
vừa chọn. Các tùy chọn cài đặt này sẽ vẫn tồn tại trừ khi bạn đặt lại về trạng thái ban đầu.
Việc làm cho ứng dụng Truyền của bạn tương thích với Android TV yêu cầu rất ít
công việc bổ sung. Dưới đây là một số đề xuất và sai lầm phổ biến nên tránh trong
để đảm bảo ứng dụng của bạn tương thích với Android TV:
Hãy lưu ý rằng chuỗi tác nhân người dùng chứa cả "Android" và "CrKey";
một số trang web có thể chuyển hướng tới một trang web chỉ dành cho thiết bị di động vì chúng phát hiện
"Android" . Đừng giả định rằng "Android" luôn trong chuỗi tác nhân người dùng
cho biết người dùng thiết bị di động.
Ngăn xếp nội dung nghe nhìn của Android có thể sử dụng GZIP rõ ràng để tìm nạp dữ liệu. Đảm bảo
dữ liệu nội dung đa phương tiện của bạn có thể phản hồi Accept-Encoding: gzip.
Sự kiện nội dung đa phương tiện HTML5 cho Android TV có thể được kích hoạt theo các thời gian khác với
Chromecast, điều này có thể cho thấy các sự cố đã được ẩn trên Chromecast.
Khi cập nhật nội dung nghe nhìn, hãy sử dụng các sự kiện liên quan đến nội dung nghe nhìn được <audio>/<video> kích hoạt
như timeupdate, pause và waiting.
Tránh sử dụng các sự kiện liên quan đến kết nối mạng như progress, suspend và
stalled, vì những chỉ số này có xu hướng phụ thuộc vào nền tảng.
Khi định cấu hình chứng chỉ HTTPS của trang web Trình nhận web, hãy đảm bảo
bao gồm chứng chỉ CA trung gian. Xem
Trang kiểm tra SSL của Qualsys để
xác minh: liệu đường dẫn chứng nhận đáng tin cậy cho trang web của bạn có bao gồm CA hay không
chứng chỉ có nhãn "tải xuống bổ sung", thì chứng chỉ đó có thể không tải trên nền tảng Android
nền tảng.
Trong khi Chromecast hiển thị trang Web receiver trên mặt phẳng đồ hoạ 720p,
các nền tảng Truyền khác, bao gồm cả Android TV, có thể hiển thị trang ở độ phân giải tối đa là 1080p.
Đảm bảo trang Trình thu phát web của bạn có thể điều chỉnh tỷ lệ linh hoạt ở nhiều độ phân giải.
Sử dụng Cầu gỡ lỗi Android
Nền tảng Android TV nổi bật trên nhiều loại hàng điện tử tiêu dùng
thiết bị: TV, hộp giải mã tín hiệu số, máy chơi trò chơi, v.v.
Mỗi cấp độ có thể được định cấu hình theo cách khác nhau. Nếu bạn gặp khó khăn khi truy cập vào
tài nguyên hệ thống của Android TV thông qua giao diện người dùng của thiết bị, bạn có thể
hãy sử dụng Cầu gỡ lỗi Android (ADB) để lấy số sê-ri của thiết bị cho
đăng ký của bạn cũng như để gỡ lỗi ứng dụng của bạn. Xem Android
Cầu gỡ lỗi để tìm hiểu thêm
của bạn.
Sử dụng ADB qua Wi-Fi
Cách kết nối với thiết bị qua ADB bằng kết nối Wi-Fi:
Đảm bảo máy tính và thiết bị Android của bạn kết nối với cùng một mạng
Thiết bị TV.
Mở cửa sổ dòng lệnh rồi nhập thông tin sau:
adb connect Android TV device IP address:4321
Trên máy tính, hãy mở một thiết bị đầu cuối rồi nhập các lệnh ADB. Bạn có thể xác minh
kết nối đã được thiết lập và thiết bị Android TV đang kết nối
trên mạng bằng lệnh sau:
adb logcat
Sử dụng ADB với cáp USB
Cách kết nối với thiết bị qua ADB bằng kết nối cáp USB:
Trong hộp thoại Allow USB debugging? (Cho phép gỡ lỗi qua USB?), hãy chọn Always (Luôn cho phép) từ
máy tính này rồi chọn OK.
Trên máy tính, hãy mở một thiết bị đầu cuối rồi nhập các lệnh ADB. Bạn có thể xác minh
kết nối đã được thiết lập và thiết bị Android TV đang kết nối
trên mạng bằng lệnh sau:
adb logcat
Sử dụng ADB qua TCP/IP
ADB hoạt động mà không cần cáp USB qua TCP/IP, nhưng trước tiên bạn phải tải phiên bản Android
Địa chỉ IP của thiết bị TV. Thiết bị do nhà phát triển xử lý để theo dõi kết nối cổng ADB
tự động và có thể kết nối mà không cần khởi động cổng. Chiến lược chuẩn
thiết bị Android TV bán lẻ không tự động lắng nghe kết nối ADB; với
các thiết bị này, trước tiên bạn phải kết nối với ADB bằng cáp USB và khởi chạy
cổng.
Đảm bảo máy tính của bạn được kết nối với cùng một mạng như thiết bị Android
Thiết bị TV.
Trên máy tính, trong một thiết bị đầu cuối, hãy khởi động cổng cho TCP/IP bằng cách
nhập thông tin sau:
adb tcpip 5555
Tháo cáp USB rồi nhập thông tin sau vào thiết bị đầu cuối:
adb connect Android TV device IP address:5555
Nếu thiết bị của bạn là Android TV do nhà phát triển gặp vấn đề, hãy làm như sau:
Đảm bảo máy tính và thiết bị Android của bạn kết nối với cùng một mạng
Thiết bị TV.
Mở cửa sổ dòng lệnh rồi nhập thông tin sau:
adb connect Android TV device IP address:4321
Trên Android TV, trong hộp thoại Allow USB debugging? (Cho phép gỡ lỗi qua USB?), hãy chọn Always (Luôn luôn)
cho phép trên máy tính này rồi chọn OK. Bạn có thể xác minh kết nối
được thiết lập và thiết bị Android TV đang giao tiếp qua
mạng bằng lệnh sau:
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eExisting Google Cast applications are compatible with Android TV without requiring modifications.\u003c/p\u003e\n"],["\u003cp\u003eBefore developing for Android TV, create a Cast application for Chromecast as a prerequisite.\u003c/p\u003e\n"],["\u003cp\u003eTo debug a Web Receiver on Android TV, connect through ADB and use Chrome DevTools (chrome://inspect).\u003c/p\u003e\n"],["\u003cp\u003eEnsure your Web Receiver handles various resolutions and potential user-agent string issues for compatibility.\u003c/p\u003e\n"],["\u003cp\u003eAndroid TV supports ADB debugging via USB, Wi-Fi, or TCP/IP for easier development and troubleshooting.\u003c/p\u003e\n"]]],[],null,["# Android TV with Google Cast\n\nWith the release of Android 5.0 comes Android TV, which supports Google Cast.\nThis document describes what you need to do to set up and test on Android TV\nwhen developing Cast applications. Your existing Cast application runs on\nAndroid TV with no additional effort. If you are developing a Cast application\nfor the first time, review the [Google Cast documentation](/cast/docs/developers)\nand develop your Cast application to run on a Chromecast device first before\ndeveloping and testing with Android TV.\n| **Note:** This document assumes that you have already developed an application that runs on a Chromecast device, as that is a mandatory first step toward having your Cast application running on Android TV.\n\nSetting up for development\n--------------------------\n\n1. Set up your Android TV device:\n 1. Connect the Android TV device to the local network.\n 2. Sign into your Google account.\n2. From the **Settings** , in the **Device** row, select **About**.\n3. Scroll down to and click on **Build** several times until a dialog appears with the message, \"You are now a developer.\"\n4. If USB debugging:\n 1. Install the USB cable, but don't connect the master end of the USB cable to your computer just yet.\n 2. In the **Preferences** row, select **Developer options** , select **USB debugging** , and select **On**.\n5. Navigate back to the home screen. You must do this to apply the settings you just selected. The settings will persist unless you perform a factory reset.\n6. Register your Android TV device on the [Google Cast SDK Developer Console](https://cast.google.com/publish), as described in [Device Registration](/cast/docs/registration#RegisterDevice).\n\nDebugging\n---------\n\nTo test and debug your Web Receiver application on your Android TV device, do the\nfollowing:\n\n1. Register your Android TV device and your application on the [Google Cast SDK Developer Console](https://cast.google.com/publish). See [Registration](/cast/docs/registration) for more information about registering devices and applications.\n2. Start your sender application and cast to the Android TV device.\n3. Connect to your Android TV device via ADB, as described in [Using Android Debug Bridge](#using_android_debug_bridge).\n4. On your development machine, open a Chrome browser window and navigate to **chrome://inspect** . **Note:** This is different than the [debugging option for a Chromecast device](/cast/docs/debugging#chrome_remote_debugger), where you navigate to your Web Receiver's IP address on port 9222.\n5. Click the **inspect** link to bring the Web Receiver into the debugger.\n6. In the Chrome Remote Debugger console, enable debug logging by entering the\n following:\n\n cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);\n\nSee [Debugging](/cast/docs/debugging) for more information.\n\nGuidelines for Android TV compatibility\n---------------------------------------\n\nMaking your Cast application compatible with Android TV requires very little\nadditional work. Here are some recommendations and common pitfalls to avoid in\norder to ensure your application is compatible with Android TV:\n\n- Be aware that the user-agent string contains both \"Android\" and \"CrKey\"; some sites may redirect to a mobile-only site because they detect the \"Android\" label. Don't assume that \"Android\" in the user-agent string always indicates a mobile user.\n- Android's media stack may use transparent GZIP for fetching data. Make sure your media data can respond to `Accept-Encoding: gzip`.\n- Android TV HTML5 media events may be triggered in different timings than Chromecast, this may reveal issues that were hidden on Chromecast.\n- When updating the media, use media related events fired by `\u003caudio\u003e/\u003cvideo\u003e` elements, like `timeupdate`, `pause` and `waiting`. Avoid using networking related events like `progress`, `suspend` and `stalled`, as these tend to be platform dependent.\n- When configuring your Web Receiver site's HTTPS certificates, be sure to include intermediate CA certificates. See the [Qualsys SSL test page](https://www.ssllabs.com/ssltest/analyze.html) to verify: if the trusted certification path for your site includes a CA certificate labelled \"extra download\", then it may not load on Android-based platforms.\n- While Chromecast displays the Web Receiver page on a 720p graphics plane, other Cast platforms including Android TV may display the page up to 1080p. Ensure your Web Receiver page scales gracefully at different resolutions.\n\nUsing Android Debug Bridge\n--------------------------\n\nThe Android TV platform is featured on many kinds of consumer electronics\ndevices: televisions, set-top boxes, gaming consoles and so forth.\nEach may be configured differently. If you are having difficulty accessing the\nAndroid TV system resources through the device's user interface, you may\nuse the Android Debug Bridge (ADB) to obtain your device's serial number for\nregistration, as well as to debug your application. See [Android\nDebug Bridge](http://developer.android.com/tools/help/adb.html) for more\ninformation.\n\n### Using ADB over Wi-Fi\n\nTo connect to your device via ADB with a Wi-Fi connection:\n\n1. On your Android TV device, enabled developer options as described in [Setting up for development](#setting_up_for_development).\n2. Be sure your computer is connected to the same network as your Android TV device.\n3. Open a terminal and enter the following:\n\n ```\n adb connect Android TV device IP address:4321\n ```\n4. On your computer, open a terminal and enter ADB commands. You can verify the\n connection is established and that the Android TV device is communicating\n across the network with the following command:\n\n ```\n adb logcat\n ```\n\n### Using ADB with a USB cable\n\nTo connect to your device via ADB with a USB cable connection:\n\n1. Set up your Android TV device for development, as described in [Setting up for development](#setting_up_for_development).\n2. Connect the master end of the USB cable to your computer.\n3. In the **Allow USB debugging?** dialog, select **Always** allow from this computer, and select **OK**.\n4. On your computer, open a terminal and enter ADB commands. You can verify the\n connection is established and that the Android TV device is communicating\n across the network with the following command:\n\n ```\n adb logcat\n ```\n\n### Using ADB over TCP/IP\n\nADB works without a USB cable, over TCP/IP, but you must first get the Android\nTV device's IP address. Developer-issue devices listen for ADB port connections\nautomatically and can be connected without initializing the port. Standard\nretail Android TV devices do not listen for ADB connections automatically; for\nthese devices, you must first connect to ADB with a USB cable and initialize\nthe port.\n\n1. Set up your Android TV device for development, as described in [Setting up for development](#setting_up_for_development).\n2. On the Android TV, in the **Device** row, select **Network** \\\u003e **Wi-Fi**, and select the connected network.\n3. Select **Status info** and note the **IP address**.\n4. If your device is a standard, retail Android TV device, do the following:\n\n 1. Follow the steps under [Using ADB with a USB cable](#using_adb_with_a_usb_cable).\n 2. Be sure your computer is connected to the same network as the Android TV device.\n 3. On your computer, in a terminal, initialize the port for TCP/IP by\n entering the following:\n\n ```\n adb tcpip 5555\n ```\n 4. Remove the USB cable, and enter the following in the terminal:\n\n ```\n adb connect Android TV device IP address:5555\n ```\n5. If your device is a developer-issue Android TV, do the following:\n\n 1. Be sure your computer is connected to the same network as your Android TV device.\n 2. Open a terminal and enter the following:\n\n ```\n adb connect Android TV device IP address:4321\n ```\n6. On the Android TV, in the **Allow USB debugging?** dialog, select **Always\n allow from this computer** , and select **OK**. You can verify the connection\n is established and that the Android TV device is communicating across the\n network with the following command:\n\n ```\n adb logcat\n ```"]]