네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.

Slides:



Advertisements
Similar presentations
Programming with Android: Network Operations
Advertisements

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.
Programming with Android: Network Operations Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Performance measurements for inter-process communication.
Android Application Development Tutorial. Topics Lecture 5 Overview Overview of Networking Programming Tutorial 2: Downloading from the Internet.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Introduction to Windows Store app development for Android programmers
UART Test UNIT 14 로봇 SW 교육원 조용수. 학습 목표 UART Init UART Send UART Receive UART -> Debugging Console Up/Down Game 제작 2.
Mobile Programming Lecture 14 Communicating via the Internet.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Cosc 4730 Brief return Sockets And HttpClient (and with AsyncTask) DownloadManager.
로봇 모니터링 2/2 UNIT 21 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Broadcasting Service 2.
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.
Android Accessing GPS Ken Nguyen Clayton State University 2012.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Networking Android Club Networking AsyncTask HttpUrlConnection JSON Parser.
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.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Asynchronous Tasks with Android Anthony Dahanne, Ing Jr identi.ca/twitter blog : Android Montreal, le 01/09/2010.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
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.
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Robolectric (version 2.4 기준 ). class AbcTest public static void setUpOnce() { public void public void testA()
UNIT 29 MCU Project 로봇 SW 교육원 조용수.
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
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.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Custom Widget 1 UNIT 26 로봇 SW 콘텐츠 교육원 조용수. 캔버스 public void drawColor(int color) 2 public class ControllerView extends View { public ControllerView(Context.
UNIT 30 네트워크 전송 2 로봇 SW 콘텐츠 교육원 조용수.
ALAA M. ALSALEHI SOFTWARE ENGINEER AT IUG Multithreading in Android.
데이터 저장 & Fragment UNIT 28 로봇 SW 콘텐츠 교육원 조용수. 데이터 저장 & Fragment SharedPreference 로 데이터 저장 Fragment 의 이해 2.
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.
State Design Pattern. Behavioral Pattern Allows object to alter its behavior when internal state changes Uses Polymorphism to define different behaviors.
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
David Sutton MOBILE INTERNET. OUTLINE  This week’s app – an RSS feed reader  Mobile internet considerations  Threads (recap)  RSS feeds  Using AsyncTask.
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
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.
Android aplikacija i baze podataka
Stock Market Quotes – Socket Version
Concurrency in Android
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
Concurrency in Android
Android – Read/Write to External Storage
Reactive Android Development
CS499 – Mobile Application Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
Mobile Computing With Android ACST 4550 Android Database Storage
Android Topics Asynchronous Callsbacks
Android Developer Fundamentals V2
Android Developer Fundamentals V2
Threads, Handlers, and AsyncTasks
CIS 470 Mobile App Development
// Please Setting App_name to Send Successful
Android Threads Dimitar Ivanov Mobile Applications with Android
程式範例 - Android String url = "
Presentation transcript:

네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수

학습 목표 Android Network 통신 2

Network Permission App 에서 Network 를 사용하기 위해서는 Permission 을 설정해야 한다. 3

Network Status Android 에서 사용 가능한 Network 를 검색 모바일 기기는 사용량에 따라 금액을 지불해야 하 므로, 현재 가능한 네트워크 (WiFi, 3G 등 ) 을 체크해 야 한다. 4

Network Status 5 public static int checkStatus(Context context) { final ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); final android.net.NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); final android.net.NetworkInfo wimax = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIMAX); final android.net.NetworkInfo ethernet = connMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET); if(wifi.isAvailable()) { return ConnectivityManager.TYPE_WIFI; } else if(mobile.isAvailable()) { return ConnectivityManager.TYPE_MOBILE; } else if(mobile.isAvailable()) { return ConnectivityManager.TYPE_MOBILE; } else { return ConnectivityManager.TYPE_DUMMY; }

Http 전송 방식 Http 정보 전달 방식 –GET 주소 줄 뒤쪽으로 전달 파라메타가 연결되는 타입 전달 길이가 제한되어, 많은 양의 데이터 전송이 어려움. 주소가 String 으로 전달되어 전달 파라메타가 노출됨. –POST 포함되는 파라메타가 Body 에 포함되어 전달됨. 다량의 데이터 전송이 가능. 주소에 데이터가 노출되지 않음 6

HttpClient 7 BufferedReader in = null; StringBuffer sb = new StringBuffer(""); Log.d("HTTP", "Request"); try{ HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(params[0]); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; String NL = System.getProperty("line.separator"); while((line = in.readLine())!= null) { sb.append(line + NL); } in.close(); String page = sb.toString(); Log.d("HTTP", "OUTPUT:" + page); } catch(Exception e) { } finally { if(in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return sb.toString();

Http 제약사항 8 네트워크 응답 시간 문제 : ANR Android 3.0 이후 Foreground 에서 Network 전송 금지. Background Thread 사용 –UI 갱신 위해 Handler 사용 AsyncTask ?

HttpClient 9 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvText = (TextView) findViewById(R.id.text); checkStatus(this); new Thread() { public void run() { BufferedReader in = null; StringBuffer sb = new StringBuffer(""); Log.d("HTTP", "Request"); try { … String page = sb.toString(); Log.d("HTTP", "OUTPUT:" + page); } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }; }.start();

AsyncTask ? Thread 처리 시 Progress 상태와 Thread 결과에 대 해서 UI 반영을 지원하는 Class doInBackground 제외한 메소드에서 UI 작업 가능 10 private class HttpAsyncTask extends AsyncTask protected String doInBackground(String... params) { return null protected void onPostExecute(String result) { protected void onPreExecute() { protected void onProgressUpdate(Integer... values) { }

AsyncTask Params AsyncTask –Params : Background 작업에 필요한 파라메타 –Progress : 작업 진행표시에 사용되는 Data Type –Result : 작업 결과로 리턴 할 데이터 타입 11 private class HttpAsyncTask extends AsyncTask protected String doInBackground(String... params) { return null protected void onPostExecute(String result) { protected void onPreExecute() { protected void onProgressUpdate(Integer... values) { }

AsyncTask 를 이용한 HttpClient 12 private class HttpAsyncTask extends AsyncTask protected String doInBackground(String... params) { // TODO Auto-generated method stub BufferedReader in = null; StringBuffer sb = new StringBuffer(""); Log.d("HTTP", "Request"); try{ … } catch(Exception e) { } finally { … } return sb.toString(); protected void onPostExecute(String result) { // TODO Auto-generated method stub tvText.setText(result); ParseJson(result); protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); protected void onProgressUpdate(Integer... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); }

실습 1: Http 연결 Http Client 로 연결하기 –Thread 사용 –Async Task 사용 13