Thực hiện các thao tác mạng bằng Cronet
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.
Cronet là ngăn xếp mạng Chromium được cung cấp cho các ứng dụng Android dưới dạng thư viện. Cronet tận dụng nhiều công nghệ giúp giảm độ trễ và tăng công suất các yêu cầu mạng mà ứng dụng của bạn cần để hoạt động.
Thư viện Cronet xử lý các yêu cầu ứng dụng được hàng triệu người sử dụng hằng ngày, chẳng hạn như YouTube, Ứng dụng Google, Google Photos và Maps – Chỉ đường và phương tiện công cộng.
Tính năng
- Hỗ trợ giao thức
- Cronet hỗ trợ sẵn các giao thức HTTP, HTTP/2 và HTTP/3 qua các giao thức QUIC.
- Yêu cầu ưu tiên
- Thư viện cho phép bạn thiết lập thẻ ưu tiên cho các yêu cầu. Máy chủ có thể dùng thẻ ưu tiên để xác định thứ tự xử lý các yêu cầu.
- Lưu tài nguyên vào bộ nhớ đệm
- Cronet có thể sử dụng bộ nhớ đệm trong bộ nhớ hoặc bộ nhớ đệm của ổ đĩa để lưu trữ tài nguyên được truy xuất trong các yêu cầu mạng. Các yêu cầu tiếp theo sẽ được tự động phân phát từ bộ nhớ đệm.
- Yêu cầu không đồng bộ
- Theo mặc định, các yêu cầu mạng được đưa ra bằng Thư viện Cronet không đồng bộ.
Các luồng worker của bạn không bị chặn trong khi chờ yêu cầu quay lại.
- Nén dữ liệu
- Cronet hỗ trợ nén dữ liệu bằng Định dạng dữ liệu nén Brotli.
Để tìm hiểu cách sử dụng Thư viện Cronet trong ứng dụng dành cho Android, hãy xem phần Gửi một yêu cầu đơn giản. Bạn cũng có thể duyệt xem Cronet Sample (Mẫu Cronet) trên GitHub.
Bạn có thể gửi ý kiến phản hồi về Thư viện Cronet bằng Công cụ theo dõi lỗi Chromium. Hãy kiểm tra danh sách lỗi trong công cụ theo dõi lỗi để đảm bảo rằng vấn đề của bạn chưa được báo cáo. Nếu vấn đề chưa được báo cáo, hãy báo cáo lỗi có từ Cronet trong dòng tóm tắt.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],null,["# Perform network operations using Cronet\n\nCronet is the Chromium network stack made available to Android apps as a\nlibrary. Cronet takes advantage of multiple technologies that reduce the latency\nand increase the throughput of the network requests that your app needs to work.\n\nThe Cronet Library handles the requests of apps used by millions of people on a\ndaily basis, such as\n[YouTube](https://play.google.com/store/apps/details?id=com.google.android.youtube),\n[Google App](https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox),\n[Google Photos](https://play.google.com/store/apps/details?id=com.google.android.apps.photos),\nand [Maps - Navigation \\& Transit](https://play.google.com/store/apps/details?id=com.google.android.apps.maps).\n\nFeatures\n--------\n\n**Protocol support**\n: Cronet natively supports the\n [HTTP](https://tools.ietf.org/html/rfc2616),\n [HTTP/2](https://tools.ietf.org/html/rfc7540), and\n [HTTP/3 over QUIC](https://www.chromium.org/quic) protocols.\n\n**Request prioritization**\n: The library allows you to set a priority tag for the requests. The server can\n use the priority tag to determine the order in which to handle the requests.\n\n**Resource caching**\n: Cronet can use an in-memory or disk cache to store resources retrieved in\n network requests. Subsequent requests are served from the cache automatically.\n\n**Asynchronous requests**\n: Network requests issued using the Cronet Library are asynchronous by default.\n Your worker threads aren't blocked while waiting for the request to come back.\n\n**Data compression**\n: Cronet supports data compression using the\n [Brotli Compressed Data Format](https://tools.ietf.org/html/rfc7932).\n\nTo learn how to use the Cronet Library in your app for Android, see [Send a\nsimple request](/develop/connectivity/cronet/start). You can also\nbrowse the\n[Cronet Sample](https://github.com/GoogleChromeLabs/cronet-sample)\non GitHub.\n\nYou can send feedback about the Cronet Library using the [Chromium Issue\nTracker](https://crbug.com). Check the list of bugs in the issue tracker to make\nsure that your issue hasn't already been reported. If your issue hasn't been\nreported, file a bug with the word *Cronet* in the summary line."]]