OLD | NEW |
1 # Quick Start Guide to Using Cronet | 1 # Quick Start Guide to Using Cronet |
2 Cronet is the networking stack of Chromium put into a library for use on | 2 Cronet is the networking stack of Chromium put into a library for use on |
3 mobile. This is the same networking stack that is used in the Chrome browser | 3 mobile. This is the same networking stack that is used in the Chrome browser |
4 by over a billion people. It offers an easy-to-use, high performance, | 4 by over a billion people. It offers an easy-to-use, high performance, |
5 standards-compliant, and secure way to perform HTTP requests. Cronet has support | 5 standards-compliant, and secure way to perform HTTP requests. Cronet has support |
6 for both Android and iOS. On Android, Cronet offers its own Java asynchronous | 6 for both Android and iOS. On Android, Cronet offers its own Java asynchronous |
7 API as well as support for the [java.net.HttpURLConnection] API. | 7 API as well as support for the [java.net.HttpURLConnection] API. |
8 This document gives a brief introduction to using these two Java APIs. | 8 This document gives a brief introduction to using these two Java APIs. |
9 | 9 |
10 ### Basics | 10 ### Basics |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 } | 51 } |
52 | 52 |
53 @Override | 53 @Override |
54 public void onSucceeded(UrlRequest request, | 54 public void onSucceeded(UrlRequest request, |
55 UrlResponseInfo responseInfo) { | 55 UrlResponseInfo responseInfo) { |
56 // Request has completed successfully! | 56 // Request has completed successfully! |
57 } | 57 } |
58 | 58 |
59 @Override | 59 @Override |
60 public void onFailed(UrlRequest request, | 60 public void onFailed(UrlRequest request, |
61 UrlResponseInfo responseInfo, UrlRequestException error) { | 61 UrlResponseInfo responseInfo, CronetException error) { |
62 // Request has failed. responseInfo might be null. | 62 // Request has failed. responseInfo might be null. |
63 Log.e("MyCallback", "Request failed. " + error.getMessage()); | 63 Log.e("MyCallback", "Request failed. " + error.getMessage()); |
64 // Maybe handle error here. Typical errors include hostname | 64 // Maybe handle error here. Typical errors include hostname |
65 // not resolved, connection to server refused, etc. | 65 // not resolved, connection to server refused, etc. |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 Make a request like this: | 69 Make a request like this: |
70 | 70 |
71 CronetEngine.Builder engineBuilder = new CronetEngine.Builder(getContext()); | 71 CronetEngine.Builder engineBuilder = new CronetEngine.Builder(getContext()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 see {@link org.chromium.net.CronetEngine#createURLStreamHandlerFactory} for | 160 see {@link org.chromium.net.CronetEngine#createURLStreamHandlerFactory} for |
161 more information). | 161 more information). |
162 You can configure Cronet and control caching through the | 162 You can configure Cronet and control caching through the |
163 `CronetEngine.Builder` instance, `engineBuilder` | 163 `CronetEngine.Builder` instance, `engineBuilder` |
164 (See [Configuring Cronet](#configuring-cronet) section), before you build the | 164 (See [Configuring Cronet](#configuring-cronet) section), before you build the |
165 `CronetEngine` and then call `CronetEngine.createURLStreamHandlerFactory()`. | 165 `CronetEngine` and then call `CronetEngine.createURLStreamHandlerFactory()`. |
166 | 166 |
167 [ByteBuffer]: https://developer.android.com/reference/java/nio/ByteBuffer.html | 167 [ByteBuffer]: https://developer.android.com/reference/java/nio/ByteBuffer.html |
168 [chrome://net-internals#import]: chrome://net-internals#import | 168 [chrome://net-internals#import]: chrome://net-internals#import |
169 [java.net.HttpURLConnection]: https://developer.android.com/reference/java/net/H
ttpURLConnection.html | 169 [java.net.HttpURLConnection]: https://developer.android.com/reference/java/net/H
ttpURLConnection.html |
OLD | NEW |