1 2Android NetworkConnect Sample 3=================================== 4 5This sample demonstrates how to connect to the network and fetch raw HTML using 6HttpsURLConnection. AsyncTask is used to perform the fetch on a background thread. 7 8Introduction 9------------ 10 11This sample demonstrates how to connect to the network and fetch raw HTML using 12[`HttpsURLConnection`][4]. Since API 11, it is required by default that all network 13operations run on a background thread in order to avoid hanging on the UI thread. Only 14when the network response is ready should the work return to the main thread to update 15the UI. An [`AsyncTask`][3] is a viable background task manager that is used to perform 16the network operation and return to the UI thread upon completion. 17 18The sample also utilizes the [`ConnectivityManager`][1] to determine if you have 19a network connection, and if so, what type of connection it is. 20 21Using an [`AsyncTaskLoader`][6] or an [`IntentService`][5] are two common alternatives 22for managing longer running background work. 23 24[1]: https://developer.android.com/reference/android/net/ConnectivityManager.html 25[2]: https://developer.android.com/reference/android/net/NetworkInfo.html 26[3]: https://developer.android.com/reference/android/os/AsyncTask.html 27[4]: https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html 28[5]: https://developer.android.com/reference/android/app/IntentService.html 29[6]: https://developer.android.com/reference/android/content/AsyncTaskLoader.html 30 31Pre-requisites 32-------------- 33 34- Android SDK 28 35- Android Build Tools v28.0.3 36- Android Support Repository 37 38Screenshots 39------------- 40 41<img src="screenshots/main.png" height="400" alt="Screenshot"/> 42 43Getting Started 44--------------- 45 46This sample uses the Gradle build system. To build this project, use the 47"gradlew build" command or use "Import Project" in Android Studio. 48 49Support 50------- 51 52- Google+ Community: https://plus.google.com/communities/105153134372062985968 53- Stack Overflow: http://stackoverflow.com/questions/tagged/android 54 55If you've found an error in this sample, please file an issue: 56https://github.com/googlesamples/android-NetworkConnect 57 58Patches are encouraged, and may be submitted by forking this project and 59submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 60 61License 62------- 63 64Copyright 2019 The Android Open Source Project, Inc. 65 66Licensed to the Apache Software Foundation (ASF) under one or more contributor 67license agreements. See the NOTICE file distributed with this work for 68additional information regarding copyright ownership. The ASF licenses this 69file to you under the Apache License, Version 2.0 (the "License"); you may not 70use this file except in compliance with the License. You may obtain a copy of 71the License at 72 73http://www.apache.org/licenses/LICENSE-2.0 74 75Unless required by applicable law or agreed to in writing, software 76distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 77WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 78License for the specific language governing permissions and limitations under 79the License. 80