SlideShare a Scribd company logo
1 of 13
Android
Connecting To Internet
Today’s agenda
Why Connect to Internet?
How to Connect to Internet?
Getting Data from Server.
Why Connect to Internet?
Two modes of apps:
● Standalone apps - Reminder/notes app, Photo editing app, Contacts app,
Music Player app.
● Connected apps - Chatting app, Food ordering app, News app, Banking apps,
Maps app.
Standalone apps More Power
Standalone Apps
Sync with server.
Access from anywhere.
Share with friends.
Save in your account.
Upload on server as
backup. Access from
anywhere.
Search for online
music, search for song
lyrics. Save
preferences online.
Contacts app
Music Player App
Reminder/notes app
Photo Editing app
Ads
Analytics
Crash reports
Push Notifications
Connecting to Network
Wi-fi: Low cost or free, high speed, large volume of data available.
3g/4g/LTE: Very Expensive, Speed may be high or low, low data volume.
Local Area Network: Connectivity to web may not be available, high speed, free.
Connecting to Internet
Permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Connecting to Internet
Checking connection status:
ConnectivityManager mgr= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
// fetch data
} else {
// display error
}
● Tells about network state
● Also notify about changes in the
state
Getting Data from Server
1. Create URL.
1. Create Connection using “HttpUrlConnection”.
1. Start Connection.
1. Read Data from Connection.
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
Code
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
URL
“A Uniform Resource Locator that identifies the location of an Internet resource.”
http://dailynews.com:8080/directory/file?search
Protocol http
Host Daiynews.com
Port 8080
Path /directory/File
Query search
String myurl = “http://facebook.com”
URL url = new URL(myurl);
HttpUrlConnection
“It is used to send and receive data over the web.”
“Data may be of any length.”
“Can be used to GET and POST data.”
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
Get Data
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
int responseCode = conn.getResponseCode(); // check if responseCode is 200
InputStream is = conn.getInputStream();
String responseData = readResponse(is); // Convert the InputStream into a string
return responseData;
Next..
Why it is important to run network operations on separate thread?
How to show network response in UI?
Parsing different data formats: Json, Images.
Handling common issues.

More Related Content

What's hot

two tier and three tier
two tier and three tiertwo tier and three tier
two tier and three tierKashafnaz2
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE teachersduniya.com
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android StudioSuyash Srijan
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
Python games
Python gamesPython games
Python gamesmolw
 
Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)Simran Kaur
 
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...Simplilearn
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Layouts in android
Layouts in androidLayouts in android
Layouts in androidDurai S
 
Object Oriented Design
Object Oriented Design Object Oriented Design
Object Oriented Design DivyaSure
 
Android Project Presentation
Android Project PresentationAndroid Project Presentation
Android Project PresentationLaxmi Kant Yadav
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programmingAmar Jukuntla
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 

What's hot (20)

Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
two tier and three tier
two tier and three tiertwo tier and three tier
two tier and three tier
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE POWER OF PYTHON PROGRAMMING LANGUAGE
POWER OF PYTHON PROGRAMMING LANGUAGE
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Python games
Python gamesPython games
Python games
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)
 
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...
Big Data Applications | Big Data Application Examples | Big Data Use Cases | ...
 
Python
PythonPython
Python
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Object Oriented Design
Object Oriented Design Object Oriented Design
Object Oriented Design
 
Android Project Presentation
Android Project PresentationAndroid Project Presentation
Android Project Presentation
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Need of object oriented programming
Need of object oriented programmingNeed of object oriented programming
Need of object oriented programming
 
What is an API?
What is an API?What is an API?
What is an API?
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 

Similar to Android Connecting to Internet

Communication in android
Communication in androidCommunication in android
Communication in androideleksdev
 
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDI
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDIINFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDI
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDIAman Dwivedi
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfRaghunathan52
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfRaghunathan52
 
abdelwahab alsammak_Chapter 1-Internet concepts.ppt
abdelwahab alsammak_Chapter 1-Internet concepts.pptabdelwahab alsammak_Chapter 1-Internet concepts.ppt
abdelwahab alsammak_Chapter 1-Internet concepts.pptDavid319172
 
Sai internet ppt
Sai   internet ppt Sai   internet ppt
Sai internet ppt Sai Swamy
 
Going Online
Going OnlineGoing Online
Going Onlinecocon5
 
The internet
The internetThe internet
The internetAniqa Zai
 
Lecture 1- Introduction to Computers and the Internet.pptx
Lecture 1- Introduction to Computers and the Internet.pptxLecture 1- Introduction to Computers and the Internet.pptx
Lecture 1- Introduction to Computers and the Internet.pptxRemyaTom2
 
Internet and services by Jaspinder Singh
Internet and services by Jaspinder SinghInternet and services by Jaspinder Singh
Internet and services by Jaspinder Singhsekhonkittu
 
Acsess and Use Internet To access and use
Acsess and Use Internet To access and  useAcsess and Use Internet To access and  use
Acsess and Use Internet To access and useTsegabrehanZerihun
 
Intrenet and its uses
Intrenet and its usesIntrenet and its uses
Intrenet and its usesRaj Parekh
 
Network Basics & Internet
Network Basics & InternetNetwork Basics & Internet
Network Basics & InternetVNSGU
 
HTML CSS web engineering slides topics
HTML CSS web engineering slides topicsHTML CSS web engineering slides topics
HTML CSS web engineering slides topicsSalman Khan
 

Similar to Android Connecting to Internet (20)

Communication in android
Communication in androidCommunication in android
Communication in android
 
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDI
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDIINFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDI
INFORMATION TECHNOLOGY FOR MANAGERS PRESENTATION BY AMAN DWIVEDI
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
Web Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdfWeb Technologies Notes - TutorialsDuniya.pdf
Web Technologies Notes - TutorialsDuniya.pdf
 
Internet
InternetInternet
Internet
 
abdelwahab alsammak_Chapter 1-Internet concepts.ppt
abdelwahab alsammak_Chapter 1-Internet concepts.pptabdelwahab alsammak_Chapter 1-Internet concepts.ppt
abdelwahab alsammak_Chapter 1-Internet concepts.ppt
 
Sai internet ppt
Sai   internet ppt Sai   internet ppt
Sai internet ppt
 
Going Online
Going OnlineGoing Online
Going Online
 
Going Online
Going OnlineGoing Online
Going Online
 
The internet
The internetThe internet
The internet
 
unit 1(chapter1).pdf
unit 1(chapter1).pdfunit 1(chapter1).pdf
unit 1(chapter1).pdf
 
Lecture 1- Introduction to Computers and the Internet.pptx
Lecture 1- Introduction to Computers and the Internet.pptxLecture 1- Introduction to Computers and the Internet.pptx
Lecture 1- Introduction to Computers and the Internet.pptx
 
unit oe 1.pdf
unit oe 1.pdfunit oe 1.pdf
unit oe 1.pdf
 
Internet and services by Jaspinder Singh
Internet and services by Jaspinder SinghInternet and services by Jaspinder Singh
Internet and services by Jaspinder Singh
 
Http_Protocol.pptx
Http_Protocol.pptxHttp_Protocol.pptx
Http_Protocol.pptx
 
Acsess and Use Internet To access and use
Acsess and Use Internet To access and  useAcsess and Use Internet To access and  use
Acsess and Use Internet To access and use
 
Intrenet and its uses
Intrenet and its usesIntrenet and its uses
Intrenet and its uses
 
Network Basics & Internet
Network Basics & InternetNetwork Basics & Internet
Network Basics & Internet
 
How Internet Work
How Internet WorkHow Internet Work
How Internet Work
 
HTML CSS web engineering slides topics
HTML CSS web engineering slides topicsHTML CSS web engineering slides topics
HTML CSS web engineering slides topics
 

More from Paramvir Singh

Ai and using ml in mobile apps
Ai and using ml in mobile appsAi and using ml in mobile apps
Ai and using ml in mobile appsParamvir Singh
 
AI in image recognition
AI in image recognition AI in image recognition
AI in image recognition Paramvir Singh
 
Android gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir SinghAndroid gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir SinghParamvir Singh
 
Dependency injection and dagger2 in android paramvir singh
Dependency injection and dagger2 in android   paramvir singhDependency injection and dagger2 in android   paramvir singh
Dependency injection and dagger2 in android paramvir singhParamvir Singh
 
Android: Network optimization by Paramvir Singh
Android:  Network optimization by Paramvir SinghAndroid:  Network optimization by Paramvir Singh
Android: Network optimization by Paramvir SinghParamvir Singh
 
Android Session 6 - UI Part 1
Android Session 6 - UI Part 1Android Session 6 - UI Part 1
Android Session 6 - UI Part 1Paramvir Singh
 
Android Connecting to internet Part 2
Android  Connecting to internet Part 2Android  Connecting to internet Part 2
Android Connecting to internet Part 2Paramvir Singh
 
Android Starting App Development
Android  Starting App DevelopmentAndroid  Starting App Development
Android Starting App DevelopmentParamvir Singh
 
Android one, why it is important for Android developers in India
Android one, why it is important for Android developers in IndiaAndroid one, why it is important for Android developers in India
Android one, why it is important for Android developers in IndiaParamvir Singh
 
Clean code, Better coding practices
Clean code, Better coding practicesClean code, Better coding practices
Clean code, Better coding practicesParamvir Singh
 
Android enterprise application development
Android enterprise application developmentAndroid enterprise application development
Android enterprise application developmentParamvir Singh
 
Near field communication
Near field communicationNear field communication
Near field communicationParamvir Singh
 

More from Paramvir Singh (13)

Ai and using ml in mobile apps
Ai and using ml in mobile appsAi and using ml in mobile apps
Ai and using ml in mobile apps
 
AI in image recognition
AI in image recognition AI in image recognition
AI in image recognition
 
Android gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir SinghAndroid gps, location services, camera and sensors - Paramvir Singh
Android gps, location services, camera and sensors - Paramvir Singh
 
Dependency injection and dagger2 in android paramvir singh
Dependency injection and dagger2 in android   paramvir singhDependency injection and dagger2 in android   paramvir singh
Dependency injection and dagger2 in android paramvir singh
 
Android: Network optimization by Paramvir Singh
Android:  Network optimization by Paramvir SinghAndroid:  Network optimization by Paramvir Singh
Android: Network optimization by Paramvir Singh
 
Android Session 6 - UI Part 1
Android Session 6 - UI Part 1Android Session 6 - UI Part 1
Android Session 6 - UI Part 1
 
Android ui part 2
Android ui part 2Android ui part 2
Android ui part 2
 
Android Connecting to internet Part 2
Android  Connecting to internet Part 2Android  Connecting to internet Part 2
Android Connecting to internet Part 2
 
Android Starting App Development
Android  Starting App DevelopmentAndroid  Starting App Development
Android Starting App Development
 
Android one, why it is important for Android developers in India
Android one, why it is important for Android developers in IndiaAndroid one, why it is important for Android developers in India
Android one, why it is important for Android developers in India
 
Clean code, Better coding practices
Clean code, Better coding practicesClean code, Better coding practices
Clean code, Better coding practices
 
Android enterprise application development
Android enterprise application developmentAndroid enterprise application development
Android enterprise application development
 
Near field communication
Near field communicationNear field communication
Near field communication
 

Recently uploaded

Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Niamh verma
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...wyqazy
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 

Recently uploaded (7)

Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Shalimar Bagh Delhi reach out to us at 🔝8264348440🔝
 
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
Chandigarh Call Girls Service ❤️🍑 9115573837 👄🫦Independent Escort Service Cha...
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
哪里有卖的《俄亥俄大学学历证书+俄亥俄大学文凭证书+俄亥俄大学学位证书》Q微信741003700《俄亥俄大学学位证书复制》办理俄亥俄大学毕业证成绩单|购买...
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 

Android Connecting to Internet

  • 2. Today’s agenda Why Connect to Internet? How to Connect to Internet? Getting Data from Server.
  • 3. Why Connect to Internet? Two modes of apps: ● Standalone apps - Reminder/notes app, Photo editing app, Contacts app, Music Player app. ● Connected apps - Chatting app, Food ordering app, News app, Banking apps, Maps app. Standalone apps More Power
  • 4. Standalone Apps Sync with server. Access from anywhere. Share with friends. Save in your account. Upload on server as backup. Access from anywhere. Search for online music, search for song lyrics. Save preferences online. Contacts app Music Player App Reminder/notes app Photo Editing app Ads Analytics Crash reports Push Notifications
  • 5. Connecting to Network Wi-fi: Low cost or free, high speed, large volume of data available. 3g/4g/LTE: Very Expensive, Speed may be high or low, low data volume. Local Area Network: Connectivity to web may not be available, high speed, free.
  • 6. Connecting to Internet Permissions: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  • 7. Connecting to Internet Checking connection status: ConnectivityManager mgr= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected()) { // fetch data } else { // display error } ● Tells about network state ● Also notify about changes in the state
  • 8. Getting Data from Server 1. Create URL. 1. Create Connection using “HttpUrlConnection”. 1. Start Connection. 1. Read Data from Connection. URL url = new URL(myurl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); InputStream is = conn.getInputStream();
  • 9. Code URL url = new URL(myurl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.connect(); InputStream is = conn.getInputStream();
  • 10. URL “A Uniform Resource Locator that identifies the location of an Internet resource.” http://dailynews.com:8080/directory/file?search Protocol http Host Daiynews.com Port 8080 Path /directory/File Query search String myurl = “http://facebook.com” URL url = new URL(myurl);
  • 11. HttpUrlConnection “It is used to send and receive data over the web.” “Data may be of any length.” “Can be used to GET and POST data.” HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  • 12. Get Data URL url = new URL(myurl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.connect(); int responseCode = conn.getResponseCode(); // check if responseCode is 200 InputStream is = conn.getInputStream(); String responseData = readResponse(is); // Convert the InputStream into a string return responseData;
  • 13. Next.. Why it is important to run network operations on separate thread? How to show network response in UI? Parsing different data formats: Json, Images. Handling common issues.