Home | History | Annotate | Download | only in NetworkConnect
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!--
      3  Copyright 2013 The Android Open Source Project
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9      http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16 -->
     17 <sample>
     18     <name>NetworkConnect</name>
     19     <group>Connectivity</group>
     20     <package>com.example.android.networkconnect</package>
     21 
     22 
     23 
     24     <!-- change minSdk if needed-->
     25     <minSdk>11</minSdk>
     26 
     27 
     28     <strings>
     29         <intro>
     30             <![CDATA[
     31             This sample demonstrates how to connect to the network and fetch raw HTML using
     32             HttpsURLConnection. AsyncTask is used to perform the fetch on a background thread.
     33             ]]>
     34         </intro>
     35     </strings>
     36 
     37     <template src="base"/>
     38 
     39     <metadata>
     40         <status>PUBLISHED</status>
     41         <categories>Connectivity</categories>
     42         <technologies>Android</technologies>
     43         <languages>Java</languages>
     44         <solutions>Mobile</solutions>
     45         <level>INTERMEDIATE</level>
     46         <icon>screenshots/icon-web.png</icon>
     47         <screenshots>
     48             <img>screenshots/main.png</img>
     49         </screenshots>
     50         <api_refs>
     51             <android>android.os.AsyncTask</android>
     52             <android>android.net.ConnectivityManager</android>
     53             <android>android.net.NetworkInfo</android>
     54         </api_refs>
     55 
     56         <description>
     57             <![CDATA[
     58 This sample demonstrates how to connect to the network and fetch raw HTML using
     59 HttpsURLConnection. AsyncTask is used to perform the fetch on a background thread.
     60             ]]>
     61         </description>
     62 
     63         <intro>
     64 <![CDATA[
     65 This sample demonstrates how to connect to the network and fetch raw HTML using
     66 [`HttpsURLConnection`][4]. Since API 11, it is required by default that all network
     67 operations run on a background thread in order to avoid hanging on the UI thread. Only
     68 when the network response is ready should the work return to the main thread to update
     69 the UI. An [`AsyncTask`][3] is a viable background task manager that is used to perform
     70 the network operation and return to the UI thread upon completion.
     71 
     72 The sample also utilizes the [`ConnectivityManager`][1] to determine if you have
     73 a network connection, and if so, what type of connection it is.
     74 
     75 Using an [`AsyncTaskLoader`][6] or an [`IntentService`][5] are two common alternatives
     76 for managing longer running background work.
     77 
     78 [1]: https://developer.android.com/reference/android/net/ConnectivityManager.html
     79 [2]: https://developer.android.com/reference/android/net/NetworkInfo.html
     80 [3]: https://developer.android.com/reference/android/os/AsyncTask.html
     81 [4]: https://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html
     82 [5]: https://developer.android.com/reference/android/app/IntentService.html
     83 [6]: https://developer.android.com/reference/android/content/AsyncTaskLoader.html
     84 ]]>
     85         </intro>
     86     </metadata>
     87 
     88 </sample>
     89