Programming with Android: Network Operations

Slides:



Advertisements
Similar presentations
1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Advertisements

Programming with Android: SDK install and initial setup Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Programming with Android: Activities and Intents
Programming with Android: Module Overview
Network Programming and Java Sockets
4 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: Servlets.
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
1 Working with the Bluetooth radio Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Hypertext Transfer PROTOCOL ----HTTP Sen Wang CSE5232 Network Programming.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
® Microsoft Office 2010 Browser and Basics.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Java Network Programming Vishnuvardhan.M. Dept. of Computer Science - SSBN Java Overview Object-oriented Developed with the network in mind Built-in exception.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Android Projects Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
COEN 445 Communication Networks and Protocols Lab 4
Network Programming Chapter 11 Lecture 6. Networks.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
XP Browser and Basics1. XP Browser and Basics2 Learn about Web browser software and Web pages The Web is a collection of files that reside.
Socket Programming.
1 Java Networking – Part I CS , Spring 2008/9.
1 L52 Networking (1). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
Cosc 4730 Brief return Sockets And HttpClient And AsyncTask.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Hypertext Transfer Protocol Information Systems 337 Prof. Harry Plantinga.
Browsing the World Wide Web. Spring 2002Computer Networks Applications Browsing Service Allows one to conveniently obtain and display information that.
Programming with Android: Network Operations Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Programming with Android: Android Fragments Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
By: Joel Rodriguez.  International student from Mexico  Delicias, Chihuahua Mexico  Spanish  Sports and Music.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Silverlight 2 has rich networking support SOAP/XML Web services via WCF proxies Untyped HTTP services (REST, RSS, ATOM) via HttpWebRequest and WebClient.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
1 Computer Communication & Networks Lecture 28 Application Layer: HTTP & WWW p Waleed Ejaz
Chapter 1: Introduction to Web Applications. This chapter gives an overview of the Internet, and where the World Wide Web fits in. It then outlines the.
Cosc 4730 Brief return Sockets And HttpClient (and with AsyncTask) DownloadManager.
1 CSC111H Client-Server: An Introduction Dennis Burford
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
1 Streams Files are a computer’s long term memory Need ability for programs to –get information from files –copy information from program variables to.
The Inter-network is a big network of networks.. The five-layer networking model for the internet.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
2: Application Layer 1 Chapter 2: Application layer r 2.1 Principles of network applications  app architectures  app requirements r 2.2 Web and HTTP.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 7 Omar Meqdadi Department of Computer Science and Software Engineering University of.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Network Programming. These days almost all devices.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Tiny http client and server
Network Programming Introduction
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
CS323 Android Topics Network Basics for an Android App
Hyper Text Transfer Protocol
HTTP Hypertext Transfer Protocol
Presentation transcript:

Programming with Android: Network Operations Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna 1 1

Outline Network operations: WebView Network operations: WebView and WebSettings Network operations: HTTP Client Network operations: HTTP Requests Network operations: HTTP Responses Network operations: Download Manager Network operations: TCP/UDP Sockets 2

Android: WebView Usage WebView  A View that displays web pages, including simple browsing methods (history, zoom in/out/ search, etc). Implemented by the WebView class public WebView(Context contex) Main methods: public void loadUrl(String url)  load the HTML page at url public void loadData(String data, String mimeType, string encoding)  load the HTML page contained in data (c) Luca Bedogni 2012

Android: WebView Usage (c) Luca Bedogni 2012

Android: WebView Usage By default, the WebView UI does not include any navigation button …However, callbacks methods are defined: public void goBack() public void goForward() public void reload() public void clearHistory() (c) Luca Bedogni 2012

Android: WebView Usage It is possible to modify the visualization options of a WebView through the WebSettings class. public WebSettings getSettings() Some options: void setJavaScriptEnabled(boolean) void setBuildInZoomControls(boolean) void setDefaultFontSize(int) (c) Luca Bedogni 2012

Android: HTTP Classes HTTP (HyperText Tranfer Protocol): Network protocol for exchange/transfer data (hypertext) Request/Resonse Communication Model MAIN COMMANDS HEAD GET POST PUT DELETE TRACE CONNECT (c) Luca Bedogni 2012

HttpClient  Interface for an HTTP client Android: HTTP Classes HttpClient  Interface for an HTTP client HttpRequest  Interface for an HTTP request HttpResponse  Interface for an HTTP response ResponseHandler<T>  Handler that creates an object <T> from an HTTP Response HttpContext  Context of the HTTP Request (request+response+data) (c) Luca Bedogni 2012

(DefaultHttpClient  implementation of an HttpClient) Android: HTTP Classes HttpClient  Interface for an HTTP client (DefaultHttpClient  implementation of an HttpClient) HttpClient client=new DefaultHttpClient(); Main method: The public method execute(…) performs an HTTP request, and allows to process an HTTP reply from the HTTP server. One of the signature of execute() abstract<T> T execute(HttpUriRequest request, ResponseHandler <T> responseHandler) (c) Luca Bedogni 2012

HttpRequest  Interface for an HTTP request Android: HTTP Classes HttpRequest  Interface for an HTTP request Two implementations: HttpGet  implements the GET HTTP method HttpPost  Implements the POST HTTP method HttpGet request=new HttpGet(String address); HttpGet request=new HttpGet(URI address); (c) Luca Bedogni 2012

Android: HTTP Classes ResponseHandler <T>  Interface for creating an object <T> from an HttpResponse, obtained after having executed an HttpRequest. Method to override public abstract T handleResponse (HttpResponse res) Generally, <T> is a String (HTML code) … (c) Luca Bedogni 2012

HttpPost  Implements the POST HTTP method Android: HTTP Classes HttpPost  Implements the POST HTTP method HttpPost request=new HttpPost(String address); HttpPost request=new HttpPost(URI address); Encapsulating a parameter … List<NomeValuePair> par=new ArrayList<NomeValuePair>() par.add(new BasicNameValuePair(“name”,”Marco”); HttpEntity postEntity=new UrlEncodedFormEntity(par); request.setEntity(postEntity); (c) Luca Bedogni 2012

Android: HTTP Classes Basic HTTPClient Request-Response Application … HttpClient client=new DefaultHttpClient(); HttpGet request=new HttpGet(); request.setURI(“http//www.cs.unibo.it”); try { client.execute(request, responseHandler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { } (c) Luca Bedogni 2012

Android: HTTP Classes Basic HTTPClient Request-Response Application … class MyResponseHandler implements ResponseHandler<String> { @Override public String handleResponse(HttpResponse response) { InputStream content=response.getEntity().getContent(); byte[] buffer=new byte[1024]; int numRead=0; ByteArrayOutputStream stream=new ByteArrayOutputStream(); while ((numRead=content.read(buffer))!=-1) stream.write(buffer, 0, numRead); content.close(); String result=new String(stream.toByteArray()); return result; } (c) Luca Bedogni 2012

Android: Download Manager DownloadManager  System service that handles long-run HTTP downloads. The client can specify the file to be downloaded through an URI (path). Download is conducted in background (with retries) Broadcast Intent action is sent to notify when the download completes. DownloadManager dm=(DownloadManager) getSystemService(DOWNLOAD_SERVICE); (c) Luca Bedogni 2012

Android: Download Manager The Request class is used to specify a download request to the Download Manager. Request request=new DownloadManager.Request(Uri.parse(address)); Main methods of the DownloadManager long enqueue(DownloadManager.Request) Cursor query(DownloadManager.Query) ParcelFileDescriptor openDownloadedFile(long) (c) Luca Bedogni 2012

Android: TCP/IP Communication TCP/UDP Communication  Android applications can use java.net.Socket facilities. Use socket-based programming like in Java … Class DatagramSocket  UDP Socket Classes Socket/ServerSocket  TCP socket Read/Write on Sockets through InputStream/OutputStream (c) Luca Bedogni 2012