Networking Android Club 2015. Networking AsyncTask HttpUrlConnection JSON Parser.

Slides:



Advertisements
Similar presentations
SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
Advertisements

USING ANDROID WITH THE INTERNET. Slide 2 Network Prerequisites The following must be included so as to allow the device to connect to the network The.
Threads, AsyncTasks & Handlers.  Android implements Java threads & concurrency classes  Conceptual view  Parallel computations running in a process.
Networking.  Many applications provide & use data & services via the Internet  Android includes multiple networking support classes, e.g.,  java.net.
Cosc 4730 Brief return Sockets And HttpClient And AsyncTask.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Building Apps with Connectivity & the Cloud. Connecting Devices Wirelessly Performing Network Operations Transferring Data Without Draining the Battery.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
Android UI, and Networking. Can do most networking on Android Bluetooth only on 2.0, Not supported with version 1.6.
HTTP and Threads. Download some code I’ve created an Android Project which gives examples of everything covered in this lecture. Download code here.here.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CS378 - Mobile Computing Web - WebView and Web Services.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Appendix F: Network Programming in Java ©SoftMoore ConsultingSlide 1.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
CS378 - Mobile Computing Web - WebView and Web Services.
HTTP and Threads. Download some code I’ve created an Android Project which gives examples of everything covered in this lecture. Download code here.here.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
Asynchronous Tasks with Android Anthony Dahanne, Ing Jr identi.ca/twitter blog : Android Montreal, le 01/09/2010.
HTTP and Threads. Getting Data from the Web Believe it or not, Android apps are able to pull data from the web. Developers can download bitmaps and text.
Address Book App 1. Define styles   Specify a background for a TextView – res/drawable/textview_border.xml.
Working in the Background Radan Ganchev Astea Solutions.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Android networking 1. Network programming with Android If your Android is connected to a WIFI, you can connect to servers using the usual Java API, like.
ALAA M. ALSALEHI SOFTWARE ENGINEER AT IUG Multithreading in Android.
Server - Client Communication Getting data from server.
JSON Android Club 2015.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
Which Jacket? An app by Ashley Kaminski. Yet another weather app… …but this one gives you relevant data! Returns the current weather and the weather in.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
Adding network connections. Connecting to the Network To perform the network operations, your application manifest must include the following permissions:
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
David Sutton MOBILE INTERNET. OUTLINE  This week’s app – an RSS feed reader  Mobile internet considerations  Threads (recap)  RSS feeds  Using AsyncTask.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
HUJI Post PC Workshop 5 Files, Threading, and Web Services Sasha Goldshtein
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Messaging and Networking. Objectives Send SMS messages using the Messaging app Send SMS messages programmatically from within your app Receive and consume.
Plan for today Open-Closed and Quizmaster
Android Application Web 1.
Small talk with the UI thread
Reactive Android Development
Concurrency in Android
WebView and Web Services
CSE 486/586 Distributed Systems Android Programming --- 2
Reactive Android Development
CS499 – Mobile Application Development
Clients and Servers 19-Nov-18.
Clients and Servers 1-Dec-18.
CS371m - Mobile Computing Responsiveness.
Software Engineering for Internet Applications
Mobile Computing With Android ACST 4550 Android Database Storage
Android Topics Asynchronous Callsbacks
Android Topics Threads and the MessageQueue
Android Developer Fundamentals V2
Android Developer Fundamentals V2
Threads, Handlers, and AsyncTasks
Threads in Java James Brucker.
// Please Setting App_name to Send Successful
Clients and Servers 19-Jul-19.
Clients and Servers 13-Sep-19.
Android Threads Dimitar Ivanov Mobile Applications with Android
Presentation transcript:

Networking Android Club 2015

Networking AsyncTask HttpUrlConnection JSON Parser

Thread UI thread Background thread

AsyncTask Helps us to manage process of backgroud thread Started from UI thread

AsyncTask: 3 parameters 1. Params 2. Progess 3. Result

AsyncTask: example TimeUnit.SECONDS.sleep(10);

AsyncTask: practice Create public static ProgressDialog in Activity Create AsyncTask onPreExecute: set message to dialog onPreExecute: show progress dialog onPostExecute: dismiss dialog

AsyncTask: pass data HttpTask task = new HttpTask(); task.execute(3); TimeUnit.SECONDS.sleep(params[0]);

Pass data: practice Change previous code so that it should wait twice amount of time If you pass 3, it should wait 6 seconds If 10, then 20

Networking: easiest way 1.Add permission: INTERNET 2.Create AsyncTask 3. Create HttpUrlConnection 4. Convert InputStream to String 5. Update UI 6. Start from UI

Step 1: Add permission Open AndroidManifest.xml Add this permission:

Step 2: Create AsynkTask public class HttpTask extends AsyncTask protected String doInBackground(String... params) { return null; protected void onPostExecute(String s) { } }

Step 3: HttpUrlConnection URL url = new URL(params[0]); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect();

Step 4: InputString to String InputStream stream = connection.getInputStream(); InputStreamReader isReader = new InputStreamReader(stream ); BufferedReader buffer = new BufferedReader(isReader ); StringBuilder content = new StringBuilder(); String line; while ((line = buffer.readLine()) != null) { content.append(line); }

Step 5: Update UI MainActivity.tvData.setText(s);

Step 6: Start from UI HttpTask task = new HttpTask(); String url = " task.execute(url);

HttpUrlConnection: practice 1.Create new AsyncTask 2. Get content using HttpUrlConnection 3. Convert content InputStream to String 4. Update UI 5. Pass that URL to AsyncTask

Parsing JSON: example JSONObject object = new JSONObject(s); String ip = object.getString("ip"); MainActivity.tvData.setText("My ip address is "+ip);

Parsing JSON: practice OUR_IP Show latitude Show longitude Show ISP Show country

Homework 1: Forecast.IO developer.forecast.io

Homework 2: Football- api.com Demo - EPL Free English Premier League Access limit: 1000 requests per hour Access from 1 IP address

Homework 3: Your own API Create your own API For example: calculator for communal services