introduction to android

51
อ.ออออออ อออออออออ Introduction to Android

Upload: bly

Post on 25-Feb-2016

81 views

Category:

Documents


0 download

DESCRIPTION

Introduction to Android. อ . สุ พจน์ สิง หัษ ฐิต. What is Android ?. แอน ดรอยด์ ( Android) เป็นระบบปฏิบัติการสำหรับอุปกรณ์พกพา เช่น โทรศัพท์มือถือ แท็บเล็ต คอมพิวเตอร์ เน็ตบุ๊ก เป็นต้น ซึ่งพัฒนามาจากระบบปฏิบัติการลิ นุกซ์ (Linux) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to Android

อ. สพจน สงหษฐต

Introduction to Android

Page 2: Introduction to Android

What is Android ?

แอนดรอยด (Android) เปนระบบปฏบตการสำาหรบอปกรณพกพา เชน โทรศพทมอถอ แทบเลตคอมพวเตอร เนตบก เปนตน

ซงพฒนามาจากระบบปฏบตการลนกซ (Linux) แอนดรอยด ถกพฒนาโดยบรษทแอนดรอยด (Android Inc.)

จากนนบรษทแอนดรอยดถกซอโดยกเกล และกเกลไดรวมมอกบกลมบรษททางดานฮารดแวร ซอรฟแวร

และ การสอสาร เพอจดตงองคกรความรวมมอชอวา Open Handset Alliance

Page 3: Introduction to Android

What is Android ?

Open Handset Alliance จดตงขนเพอวตถประสงคในการสรางแพลตฟอรม (Platform)

สำาหรบอปกรณพกพาทมพนฐานอยบนมาตรฐานเปด(Open Standard)

นกพฒนาสามารถพฒนาแอพพลเคชนทรนบนแอนดรอยด ไดโดยใชภาษาจาวา โดยการเขาถงความสามารถตางๆของแอนดรอยด

จะกระทำาผานทางชด Java libraries ทกเกลไดจดเตรยมไวใหในAndroid SDK

Page 4: Introduction to Android
Page 5: Introduction to Android
Page 6: Introduction to Android

Android 0.9320x480 HVGA

2008 Aug 18

Android 1.0Apple pieAPI 1.0320x480 HVGA

2008 Sep 23

Android 1.1Banana breadAPI 2.0320x480 HVGA

2009 Feb 9

Android 1.5

2009 Apr 30

CupcakeAPI 3.0Bluetooth A2DP, AVRCP supportSoft-keyboard with text-predictionRecord/watch videos320x480 HVGA

Android version history

Page 7: Introduction to Android

Android 1.6DonutAPI 4.0Gesture frameworkTurn-by-turn navigation800×480 WVGA

2009 Sep 15

Android 2.0ÉclairAPI 5.0Digital zoomLive WallpapersUpdated UI800×480 WVGA

2009 Oct 26

Android 2.2FroyoAPI 8.0Flash 10.1JIT implementationUSB TetheringApplications installation to the expandable memoryUpload file support in the browserAnimated GIFs800×480 WVGA

2010 May 20

Android version history

Page 8: Introduction to Android

Android 2.3GingerbreadAPI 9.0Near Field Communication supportNative VoIP/SIP supportVideo call support1366×768 WXGA

2010 Dec 6

Android 3.0HoneycombAPI 11.0Multi core supportBetter tablet supportUpdated 3D UI"Private browsing“Open Accessory APIUSB host APIMice, joysticks, gamepads... support

2011 Feb 22

Android version history

Page 9: Introduction to Android

Android 4.0Ice Cream SandwichAPI 14.0Facial recognition (Face Unlock)UI use Hardware accelerationWeb browser, allows up to 16 tabsUpdated launcher Android Beam exchange data through NFCResizable widgetsVideo stabilization GoogleNow

2011 Oct 19

Android 4.1Jelly Bean

Android version history

Triple buffering in the graphics pipelineExtends vsync timing across all drawing and animationCPU input boostBi-Directional Text and Other Language SupportAndroid BeamGoogle Cloud Messaging for AndroidApp EncryptionSmart App Updates

Page 10: Introduction to Android

Android Handsets

10SJU 2004-04 Android

Motorola CliqHTC G1 HTC HeroSamsung i7500

Samsung MomentMotorola DroidHTC Magic HTC Tattoo

Sony X10

Page 11: Introduction to Android

Android Architecture

แอนดรอยดเปนซอฟตแวรทมโครงสรางแบบเรยงทบซอนหรอ แบบสแตก (Stack) ซงรวมเอาระบบปฏบตการ (Operating System)

, มดเดลแวร (Middleware) และแอพพลเคชนทสำาคญเขาไวดวยกน เพอใชสำาหรบทำางานบนอปกรณพกพาเคลอนท (Mobile Devices) เชน โทรศพทมอถอ เปนตน

การทำางานของแอนดรอยดมพนฐานอยบนระบบลนกซ เคอรเนล (Linux Kernel) ซงใช Android SDK (Software Development Kit) เปนเครองมอสำาหรบการพฒนา

แอพพลเคชนบนระบบปฏบตการ Android และใชภาษา Java ในการพฒนา

Page 12: Introduction to Android
Page 13: Introduction to Android

The Kernel

Page 14: Introduction to Android

Linux kernel

• ทำาหนาทเปน Hardware Abstraction Layer คอเปนตวกลางระหวาง ฮารดแวร กบสวนของซอรฟแวรทอยถดขนไป

• ทำาหนาทบรหารจดการทรพยากรตางๆของเครอง เชน การจดการหนวยความจำา (Memory Management)

การจดการโพรเซส (Process Management) การเชอมตอเครอขาย (Networking) เปนตนฯลฯ

• ผผลตอปกรณสามารถพอรต (port) แอนดรอยดใหไปรนบนฮารดแวร แบบตางๆไดโดยเปลยนแปลงในสวนของ Linux kernel น

Page 15: Introduction to Android

Libraries

Page 16: Introduction to Android

Libraries Android ไดรวบรวมกลมของไลบรารตางๆ ทสำาคญและมความจำาเปนเอาไวมากมาย

เพออำานวยความสะดวกใหกบนกพฒนาและงายตอการพฒนาโปรแกรมโดยตวอยางของไลบรารทสำาคญเชน•System C library เปนกลมของไลบรารมาตรฐานทอยบนพนฐาน

ของภาษา C ไลบราร (libc) สำาหรบ embedded system ทมพนฐานมาจาก Linux •Media Libraries เปนกลมการทำางานมลตมเดย เชน MPEG4, H.264, MP3, AAC, AMR, JPG, และ PNG •Surface Manager เปนกลมการจดการรปแบบหนาจอ การวาดหนาจอ

Page 17: Introduction to Android

Libraries •3D/3D library เปนกลมของกราฟกแบบ 2 มต หรอSGL (Scalable Graphics Library) และแบบ 3 มต หรอ OpenGL•FreeType เปนกลมของบตแมป (Bitmap) และเวคเตอร (Vector) สำาหรบ

การเรนเดอร (Render) ภาพ•SQLite เปนกลมของฐานขอมล โดยนกพฒนาสามารถใชฐานขอมลนเกบขอมล

แอพพลเคชนตางๆ ได•Browser Engine เปนกลมของการแสดงผลบนเวบเบราเซอรโดยอยบนพนฐานของ Webkit ซงจะมลกษณะคลายกบ Google Chrome

Page 18: Introduction to Android
Page 19: Introduction to Android
Page 20: Introduction to Android

Android Runtime Dalvik Virtual Machine

20

Page 21: Introduction to Android

เปนชนยอยทอยในชนไลบราร ซงจะประกอบดวย 2 สวนหลกคอDalvik VM (Virtual Machine)  สวนนถกเขยนดวยภาษา Java เพอใชเฉพาะการใชงานในอปกรณเคลอนทDalvik VM จะแตกตางจาก Java VM (Virtual Machine) คอDalvik VM จะรนไฟล .dex ทคอมไพล มาจากไฟล .class และ .jar

โดยม tool ทชอวา dx ทำาหนาทในการบบอดคลาส Java

Android Runtime

Page 22: Introduction to Android

ทงนไฟล .dex จะมขนาดกะทดรดและเหมาะสมกบอปกรณเคลอนทมากกวา .class เพอตองการใชพลงงานจากแบตเตอรอยางมประสทธภาพสงสด

Android Runtime

Page 23: Introduction to Android

Core Java Library สวนนเปนไลบรารมาตรฐาน แตกมความแตกตางจากไลบรารของ Java SE

(Java Standard Edition) และ Java ME (Java Mobile Edition)

Android Runtime

Page 24: Introduction to Android

Application Framework & Toolkit

Page 25: Introduction to Android

ในชนนจะอนญาตใหนกพฒนาสามารถเขาเรยกใชงาน โดยผาน API (Application Programming Interface) ซงAndroid ไดออกแบบไวเพอลดความซำาซอนในการ

ใชงาน application componentโดยในชนนประกอบดวยแอพพลเคชนเฟรมเวรคดงน

Application Framework

Page 26: Introduction to Android

•View System เปนสวนทใชในการควบคมการทำางานสำาหรบการ สรางแอพพลเคชน เชน lists, grids, text boxes, buttons

และ embeddable web browser •Location Manager เปนสวนทจดการเกยวกบคาตำาแหนงของ

เครองอปกรณพกพาเคลอนท•Content Provider เปนสวนทใชควบคมการเขาถงขอมลท

มการใชงานรวมกน (Share data) ระหวางแอพพลเคชนทแตกตางกน เชน ขอมลผตดตอ (Contact)

Application Framework

Page 27: Introduction to Android

•Resource Manager เปนสวนทจดการขอมลตางๆ ทไมใชสวนของ โคดโปรแกรม เชน รปภาพ, localized strings, layout ซงจะอย

ในไดเรคทอร res/ •Notification Manager เปนสวนทควบคมอเวนต (Event) ตางๆ ทแสดงบนแถบสถานะ (Status bar) เชน ในกรณทไดรบขอความหรอ

สายทไมไดรบและการแจงเตอนอนๆ เปนตน•Activity Manager เปนสวนควบคม Life Cycle ของแอพพลเคชน

Application Framework

Page 28: Introduction to Android

Android Application

Page 29: Introduction to Android

Application Building Blocks ชนนจะเปนชนทอยบนสดของโครงสรางสถาปตยกรรม Android

ซงเปนสวนของแอพพลเคชนทพฒนาขนมาใชงาน เชน แอพพลเคชนรบ/สงอเมล, SMS, ปฏทน, แผนท, เวบเบราเซอร,

รายชอผตดตอ เปนตน ซงแอพพลเคชนจะอยในรปแบบของไฟล .apk

Page 30: Introduction to Android

User Interface

30SJU 2004-04 Android

Page 31: Introduction to Android

Sleep as android

Run keeper

Android Apps

Page 32: Introduction to Android

Shazam

gStrings

Android Apps

Page 33: Introduction to Android

Android Apps

Google skymap

Games

Page 34: Introduction to Android

Android software development-J2se JDK-Android SDK- SDK Platform- SDK Platform tools- SDK Tools- Emulator & Images- Example

-Eclipse IDE- ADT Plug-in

-ADB USB Driver-Internet connection for online install

Page 35: Introduction to Android

Emulator limitation

No support for placing or receiving actual phone calls. No support for USB connectionsNo support for camera/video capture (input).No support for device-attached headphonesNo support for determining connected stateNo support for determining battery charge levelNo support for determining SD card insertion/removalNo support for BluetoothNo support for Multitouch

Page 36: Introduction to Android

Android Open Accessory Development Kit (ADK)

Page 37: Introduction to Android

IOIO for Android

-Chainable LED-Joystick -PIR Motion Sensor -Ultra Sonic range finder -Temp&Humi Sensor -125Khz RFID Card Reader -Relay -High Sensitive Mini Servo

Page 38: Introduction to Android

การสราง AlertDialog

Page 39: Introduction to Android

การสราง AlertDialog

Page 40: Introduction to Android

การสราง AlertDialog1) import android.app.AlertDialog;2) AlertDialog.Builder adb = new AlertDialog.Builder(this);

EditText edt1 = (EditText)this.findViewById(R.id.editText1)

Button but1 = (Button)this.findViewById(id.button1);

3) but1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {4) AlertDialog ad = adb.create();

String aaa = edt1.getText().toString();ad.setMessage("Sawatdee khun : " + aaa);ad.show();}});

Page 41: Introduction to Android

การสราง Alert Text

Page 42: Introduction to Android

การสราง Alert Text

Page 43: Introduction to Android

การสราง Alert Text1) import android.widget.Toast;2) EditText editT1 = (EditText)findViewById(R.id.editText1);

Button btn1 = (Button)findViewById(R.id.button1);

3) but1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {4) Toast.makeText(MainActivity.this, String.valueOf("Your Input : " + editT1.getText().toString()), Toast.LENGTH_SHORT).show();

}});

Page 44: Introduction to Android

การIntent ทมการสงคา Result

Page 45: Introduction to Android

การIntent ทมการสงคา Result

Page 46: Introduction to Android

การIntent ทมการสงคา Result

Page 47: Introduction to Android

การIntent ทมการสงคา Result 1) Import android.content.Intent; 2) public void onClick(View v) {

Intent i = new Intent(MainActivity.this,Input.class);startActivityForResult(i,13);}

3) protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

switch (requestCode){case(13):if(resultCode==Activity.RESULT_OK) {textview.setText(data.getStringExtra("radius"));}break;

}}

Page 48: Introduction to Android

การIntent ทมการสงคา Result 1) Import android.content.Intent; 2) public void onClick(View v) {

Intent i = new Intent();i.putExtra("radius",

edittext1.getText().toString());Input.this.setResult(RESULT_OK,i);finish();}

3) protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data); }

Page 49: Introduction to Android

GPS1) ตองขอสทธACCESS_FINE_LOCATION จาก AndroidManifest.xml <uses-permission ndroid:name="android.permission.ACCESS_FINE_LOCATION"/> 2) import android.location.Location;

3) private LocationManager lm;private TextView txtv;protected void onCreate(Bundle savedInstanceState) {txtv =(TextView)this.findViewById(R.id.textView1);lm =

(LocationManager)this.getSystemService(LOCATION_SERVICE);}

4) protected void onResume() {super.onResume();

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,1500,1,this);

}

Page 50: Introduction to Android

GPS5) protected void onPause() {

super.onPause();lm.removeUpdates(this);}

6) public void onLocationChanged(Location arg0) {if(arg0 == null)txtv.append("***ไมสามารถระบตำาแหนงได***"+ "\n");else{txtv.append("ละตจด:"+ arg0.getLatitude()+ "\n");txtv.append("ลองตจด:"+ arg0.getLongitude()+ "\n");}}

Page 51: Introduction to Android

การขอ Google Maps API Key1) หาไฟล debug.keystore ใหเจอ

2) keytool -list -alias androiddebugkey -keystore <path_to_debug_keystore>.keystore -storepass android -keypass android

D:\ >keytool -list -alias androiddebugkey -keystore D:\.android\debug.keystore -storepass android -keypass android

3) ผลลพธ Certificate fingerprint (MD5): 82:48:6B:DE:82:84:8D:E0:AC:0A:6F:09:94:4F:5F:07

4) ไปท http://code.google.com/intl/th/android/maps-api-signup.html

5) Your key is 0ZI4J5um4YUPUcW4rqP2CulDXvicUXanHTZ2JPg