로봇 모니터링 2/2 UNIT 21 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Broadcasting Service 2.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
Advertisements

Services. Application component No user interface Two main uses Performing background processing Supporting remote method execution.
WiFi in Android.
Monitoring battery use. New app, BatteryMonitor Add permission: BATTERY_STATS The battery is monitored by receiving broadcasts of battery state information.
BroadcastReceiver.  Base class for components that receive and react to events  Events are represented as Intent objects  Intents received as parameter.
1 Working with the Android Services Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Broadcast intents.
Android Services Mobile Application Development Selected Topics – CPIT Oct-15.
안드로이드 프로그래밍 서비스와 방송 수신자 장 원 영 실습파일 :
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
Android ICC Part II Inter-component communication.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
Mobile Programming Lecture 6
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
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.
Android - Broadcast Receivers
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Activity 생명주기 UNIT 13 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Logcat 액티비티 생명주기를 설명할 수 있다. 현재 상태를 저장할 수 있다. 2.
Custom Widget 1 UNIT 26 로봇 SW 콘텐츠 교육원 조용수. 캔버스 public void drawColor(int color) 2 public class ControllerView extends View { public ControllerView(Context.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
데이터 저장 & Fragment UNIT 28 로봇 SW 콘텐츠 교육원 조용수. 데이터 저장 & Fragment SharedPreference 로 데이터 저장 Fragment 의 이해 2.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Mobile Programming Midterm Review
Service ANDROID CLUB Сегодня  Service Service - служба  Работает в фоновом режиме  Не имеет пользовательского интерфейса.
네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Google map v2.
Speech Service & client(Activity) 오지영.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
David Sutton SMS TELEPHONY IN ANDROID. OUTLINE  This week’s exercise, an SMS Pub Quiz  Simulating telephony on an emulator  Broadcast Intents and broadcast.
Developing Android Services. Objectives Creating a service that runs in background Performing long-running tasks in a separate thread Performing repeated.
Android Services Lesson 22 Victor Matos Cleveland State University Notes are based on: Android Developers Portions.
Intents and Broadcast Receivers
Android Introduction Hello World
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
CS499 – Mobile Application Development
Broadcast receivers.
GUI Programming Fundamentals
Android Introduction Hello World.
Cleveland State University
Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.
Android Introduction Camera.
Android Application Development android.cs.uchicago.edu
Picasso Revisted.
Developing Android Services
CIS 470 Mobile App Development
null, true, and false are also reserved.
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
Activities and Intents
滑動 建國科技大學 資管系 饒瑞佶.
CIS 470 Mobile App Development
Android Developer Fundamentals V2 Lesson 5
Service Services.
CIS 470 Mobile App Development
Activities, Fragments, and Intents
Mobile Programming Broadcast Receivers.
Presentation transcript:

로봇 모니터링 2/2 UNIT 21 로봇 SW 콘텐츠 교육원 조용수

학습 목표 Broadcasting Service 2

브로드캐스팅 3 BroadcastReceiver sendBroadcast Intent

브로드캐스팅 BroadcastReceiver –public abstract void onReceive (Context context, Intent intent) Context –public abstract Intent registerReceiver (BroadcastReceiver rec eiver, IntentFilter filter) –public abstract void unregisterReceiver (BroadcastReceiver receiver) –public abstract void sendBroadcast (Intent intent) 4

시스템 브로드캐스팅 ACTION_TIME_TICK ACTION_TIME_CHANGED ACTION_TIMEZONE_CHANGED ACTION_BOOT_COMPLETED ACTION_PACKAGE_ADDED ACTION_PACKAGE_CHANGED ACTION_PACKAGE_REMOVED ACTION_PACKAGE_RESTARTED ACTION_PACKAGE_DATA_CLEARED ACTION_UID_REMOVED ACTION_BATTERY_CHANGED ACTION_POWER_CONNECTED ACTION_POWER_DISCONNECTED ACTION_SHUTDOWN 5

시스템 브로드캐스팅 6 public class MainActivity extends RobotActivity { private Device leftEyeDevice; private Device rightEyeDevice; private BroadcastReceiver br = new BroadcastReceiver() public void onReceive(Context context, Intent intent) { if(leftEyeDevice != null && rightEyeDevice != null) { String action = intent.getAction(); if(Intent.ACTION_POWER_CONNECTED.equals(action)) { leftEyeDevice.write(0, 255); rightEyeDevice.write(0, 255); } else if(Intent.ACTION_POWER_DISCONNECTED.equals(action)) { leftEyeDevice.write(0, 0); rightEyeDevice.write(0, 0); } };

시스템 브로드캐스팅 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_POWER_CONNECTED); filter.addAction(Intent.ACTION_POWER_DISCONNECTED); registerReceiver(br, filter); protected void onDestroy() { super.onDestroy(); unregisterReceiver(br); public void onInitialized(Robot robot) { super.onInitialized(robot); leftEyeDevice = robot.findDeviceById(Albert.EFFECTOR_LEFT_EYE); rightEyeDevice = robot.findDeviceById(Albert.EFFECTOR_RIGHT_EYE); }

서비스 8 Object Context ContextWrapper Service

서비스 만들기 9 public class MyService extends Service public IBinder onBind(Intent intent) { return null; }

서비스 만들기 10 <manifest xmlns:android=" package="com.example.unit23" android:versionCode="1" android:versionName="1.0" >

서비스 호출하기 ( 명시적 인텐트 ) 11 public class MainActivity extends Activity { private Intent protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent = new Intent(this, MyService.class); startService(intent); protected void onDestroy() { super.onDestroy(); stopService(intent); }

서비스 호출하기 ( 명시적 인텐트 ) 12 public class MainActivity extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startService(new Intent(this, MyService.class)); protected void onDestroy() { super.onDestroy(); stopService(new Intent(this, MyService.class)); }

서비스 생명주기 13

서비스 생명주기 14 public class MyService extends Service public void onCreate() { Log.v("Example", "onCreate"); super.onCreate(); public void onDestroy() { Log.v("Example", "onDestroy"); super.onDestroy(); public int onStartCommand(Intent intent, int flags, int startId) { Log.v("Example", "onStartCommand"); return super.onStartCommand(intent, flags, startId); public IBinder onBind(Intent intent) { return null; }

서비스 호출하기 ( 암시적 인텐트 ) 15 <manifest xmlns:android=" package="com.example.unit23" android:versionCode="1" android:versionName="1.0" >

서비스 호출하기 ( 암시적 인텐트 ) 16 public class MainActivity extends Activity { private Intent protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intent = new Intent("example.android.SERVICE"); startService(intent); protected void onDestroy() { super.onDestroy(); stopService(intent); }

서비스 호출하기 ( 암시적 인텐트 ) 17 public class MainActivity extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startService(new Intent("example.android.SERVICE")); protected void onDestroy() { super.onDestroy(); stopService(new Intent("example.android.SERVICE")); }

마이크 서비스 18 public class MyService extends Service { private MicThread public void onCreate() { super.onCreate(); thread = new MicThread(); thread.start(); public void onDestroy() { super.onDestroy(); if(thread != null) thread.cancel(); public IBinder onBind(Intent intent) { return null; }

마이크 서비스 19 private class MicThread extends Thread { private static final int FREQ = 44100; private static final int CHANNEL = AudioFormat.CHANNEL_IN_MONO; private static final int ENCODING = AudioFormat.ENCODING_PCM_16BIT; private boolean running = public void run() { int bufferSize = AudioRecord.getMinBufferSize(FREQ, CHANNEL, ENCODING) * 3; if(bufferSize <= 0) return; AudioRecord audioRecord = new AudioRecord(AudioSource.MIC, FREQ, CHANNEL, ENCODING, bufferSize); if(audioRecord.getState() != android.media.AudioRecord.STATE_INITIALIZED) { audioRecord.release(); return; } short[] audioData = new short[bufferSize]; audioRecord.startRecording();

마이크 서비스 20 int len, v; long sum; while(running) { len = audioRecord.read(audioData, 0, bufferSize); if(running == false) break; sum = 0; for(int i = 0; i < len; ++i) { v = Math.abs(audioData[i]); sum += v; } sum /= ; if(running == false) break; Intent intent = new Intent("example.intent.action.MICROPHONE"); intent.putExtra("example.intent.extra.MIC_LEVEL", (int)sum); sendBroadcast(intent); } audioRecord.stop(); audioRecord.release(); audioRecord = null; } void cancel() { running = false; }

마이크 서비스 21 public class MainActivity extends RobotActivity { private Device leftWheelDevice; private Device rightWheelDevice; private BroadcastReceiver br = new BroadcastReceiver() public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if("example.intent.action.MICROPHONE".equals(action)) { int level = intent.getIntExtra("example.intent.extra.MIC_LEVEL", 0); if(level > 100) { leftWheelDevice.write(-30); rightWheelDevice.write(-30); } else { leftWheelDevice.write(0); rightWheelDevice.write(0); } };

마이크 서비스 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); registerReceiver(br, new IntentFilter("example.intent.action.MICROPHONE")); startService(new Intent("example.android.SERVICE")); protected void onDestroy() { super.onDestroy(); unregisterReceiver(br); stopService(new Intent("example.android.SERVICE")); public void onInitialized(Robot robot) { super.onInitialized(robot); leftWheelDevice = robot.findDeviceById(Albert.EFFECTOR_LEFT_WHEEL); rightWheelDevice = robot.findDeviceById(Albert.EFFECTOR_RIGHT_WHEEL); }

마이크 서비스 23 <manifest xmlns:android=" package="com.example.unit23" android:versionCode="1" android:versionName="1.0" >

숙제 가속도 센서 서비스 만들기 – 서비스에서 폰의 가속도 센서 X 축, Y 축 값 읽기 –X 축, Y 축 값을 브로드캐스팅으로 보내기 – 액티비티에서 브로드캐스팅 받아서 로봇 움직이기 24