SlideShare a Scribd company logo
1 of 40
Download to read offline
TUTORIAL 1
Kartik Sankaran
kar.kbc@gmail.com
CS4222 Wireless and Sensor Networks
[2nd Semester 2013-14]
20th January 2014
Android Concepts and Programming
PART 1: Introduction to Android
- Simple Android Apps: HelloWorldApp and ButtonApp
PART 2: Introduction to Sensors
- Simple Sensor App: AngleApp
Goal of the Tutorials:
- Help you quickly get started with Android programming.
- Cover concepts not explained well on the Android website.
Agenda
2
What is Android?
- Linux-based Operating System for mobile devices
- Developed by Android, Inc. (later purchased by Google)
- First Android phone in October 2008
- Multiple companies producing Android phones:
Samsung, HTC, LG,
Motorola, ASUS,
and many others
Introduction to Android
3
Android is not just “Linux ported to mobile phones”
- Linux code:
< 500 MB
- Android code:
> 10 GB
Why Linux?
- Process
management
- Security
- Code can be
forked
Introduction to Android
4
Android Version History: (most phones run Jelly Bean)
Introduction to Android
5
Typical specs:
- 1 GB RAM, 16 GB flash storage, 1 GHz multi-core processor, GPU
- Have variety of sensors!
- Limited battery : approx 2000 mAh
Mobiles have limited memory (not anymore!):
- Android can kill an App taking too much memory
- Each App has an upper limit on heap space: 32 MB on Galaxy Nexus
Major battery drainers:
- Display, Processor, 3G, GPS
Introduction to Android
6
How does Android manage Applications?
- Multiple applications can run at same time
- Only one instance of an App runs at a time
- Typical buttons: Home, Back, Menu, Search
Home button:
Similar to minimizing a window (state retained)
Back button:
Similar to closing a window (state destroyed)
- After App destroyed, its still in memory!
Introduction to Android
7
How to write Applications?
- Apps are mostly written in Java.
- Compiled to Dalvik (dex) code.
(Dalvik is a village in Iceland)
Each App runs:
- On Dalvik VM
- Separate process
- Separate User ID (for security)
Why Dalvik?
- Memory Optimized
(Jar 113 KB  Dex 20 KB)
- Avoid paying money to Sun (Oracle)
Why not directly convert Java  Dex?
- Use 3rd party Java libraries
Introduction to Android
8
(Image from Marakana’s slides on Android Internals)
Installation Steps:
1. Install Java (Version 6 or above)
2. Install Android SDK
- http://developer.android.com/sdk/index.html
Your first Android program
9
If any problem, then
email/meet me
Installation Steps:
3. Install Android ‘APIs’ (needs a good internet connection, takes a while)
- http://developer.android.com/sdk/installing/adding-packages.html
- SDK Manager.exe (at root of SDK installation folder)
- API 17 + SDK tools + SDK platform tools are needed
Your first Android program
10
Installation Steps:
4. Install an IDE of your choice
a. Eclipse
- ADT Bundle has Android SDK + Eclipse IDE + ADT Plugin
http://developer.android.com/sdk/index.html
- If you already have
Eclipse (>= 3.6.2 Helios),
install the ADT plugin:
http://developer.android.com/sdk/installing/installing-adt.html
Your first Android program
11
Installation Steps:
4. Install an IDE of your choice
b. IntelliJ (approx 120 MB)
- http://www.jetbrains.com/idea/download/index.html
c. Emacs (or any text editor of your choice)
Your first Android program
12
Installation Steps:
5. Install phone’s device drivers (Mac users skip this step)
a. Windows
- http://developer.android.com/tools/extras/oem-usb.html
- http://www.samsung.com/us/support/owners/product/SCH-I515MSAVZW
b. Linux (/etc/udev/rules.d/51-android.rules)
- http://developer.android.com/tools/device.html
- SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev"
Your first Android program
13
Creating an Android project:
1. Using command line
$ android list targets (to get target IDs)
$ android create project --target 9 --name HelloWorld --path
./HelloWorld --activity HelloWorldActivity --package
nus.cs4222.helloworld
2. Using an IDE
- File New Project
- Fill in the details, similar to above
Your first Android program
14
Project Structure:
src: Your source code
res/layout/main.xml: Your GUI
libs: Library jars
In Android, the GUI screen is called
an ‘Activity’
(will be covered in detail in
next tutorial)
Your first Android program
15
res/layout/main.xml : (already created by default)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
Your first Android program
16
HelloWorldActivity.java : (already created by default)
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
// Specify what GUI to use (res/layout/main.xml)
// ‘R’ stands for ‘Resources’
setContentView( R.layout.main );
}
}
Your first Android program
17
Turn on USB debugging on the phone:
Settings  Developer Options
Enable USB Debugging
Make sure you installed the USB Driver
for this phone!
(in this case, Samsung Galaxy Nexus)
18
Build (compile) your App:
1. Using command line:
$ ant debug
2. Using an IDE:
‘Build’ button/menu
- App: bin/HelloWorld-debug.apk
Install App on phone:
1. Using command line:
$ adb install -r
bin/HelloWorld-debug.apk
2. Using an IDE:
‘Install/Run’ button/menu
19
Debugging (use the filter field most of the time):
Monitor.bat (AKA ddms.bat)
20
Adding more GUI ‘widgets’:
- EditText: User can enter text here
- Button: Pressing it triggers an action
- TextView: Displays some text
Your first Android program
21
1. Enter text here
2. Press the button
3. Text gets appended here
res/layout/main.xml : (add Button and EditText widgets)
<LinearLayout ...>
<EditText android:id="@+id/EditText_Message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<Button android:id="@+id/Button_Send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send Message" />
<TextView
android:id="@+id/TextView_Message"
... />
</LinearLayout>
Your first Android program
22
GUI layout defined using XML
Widgets have IDs
“@” Referring to a resource
“+” Adds this ID to the R class
HelloWorldActivity.java :
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate( Bundle savedInstanceState ) {
...
}
// Text View (displays messages)
private TextView textView_Message;
// Edit Text (user enters message here)
private EditText editText_Message;
// Button to trigger an action
private Button button_Send;
}
Your first Android program
23
GUI widgets in Java code
HelloWorldActivity.java :
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate( Bundle savedInstanceState ) {
...
// Get references to the GUI widgets
textView_Message =
(TextView) findViewById( R.id.TextView_Message );
editText_Message =
(EditText) findViewById( R.id.EditText_Message );
button_Send =
(Button) findViewById( R.id.Button_Send );
}
}
Your first Android program
24
HelloWorldActivity.java :
public void onCreate( Bundle savedInstanceState ) {
...
// Set the button's click listener
button_Send.setOnClickListener(
new View.OnClickListener() {
public void onClick( View v ) {
// Change the text view
String newText = textView_Message.getText() +
"n New Message: " +
editText_Message.getText();
textView_Message.setText ( newText );
}
} );
}
Your first Android program
25
Android online tutorials:
http://developer.android.com/guide/components/fundamentals.html
http://developer.android.com/training/basics/firstapp/index.html
Note: Many Android programmers directly jump into coding.
However, it is more important to understand the concepts first before
writing complex Apps. Otherwise, coding becomes a messy headache.
Your first Android program
26
Break
1. What sensors are available? What do they sense?
2. How to access sensor data in Android?
3. What are the sensor properties and characteristics?
4. Why is it important to understand each sensor’s properties?
5. Simple Sensor App: AngleApp
Introduction to Sensors
28
Sensors – What do they sense?
29
http://www.youtube.com/watch?v=C7JQ7Rpwn2k
Understanding the physics
behind the sensors
1. Motion Sensors
- Accelerometer (also: Gravity, Linear Accl)
- Gyroscope
- Rotation Vector
2. Position Sensors
- Magnetic Field
- Orientation
- Proximity
3. Environmental Sensors
- Temperature, Light, Pressure, Humidity
4. Others
- GPS, Camera, Microphone, Network
These sensors have
different APIs
May be physical or virtual
SensorManager manager = (SensorManager)
getSystemService( Context.SENSOR_SERVICE );
Sensor light = manager.getDefaultSensor( Sensor.TYPE_LIGHT );
protected void onResume() {
manager.registerListener( this, light,
SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause() {
manager.unregisterListener( this );
}
public void onSensorChanged( SensorEvent event ) {
float lux = event.values[0];
}
Sensors – How to access them in code?
30
Returns null if sensor not
present
Sampling Rate
Listener for sensor changesWhy float and not double?
LocationManager manager = (LocationManager)
getSystemService( Context.LOCATION_SERVICE );
List <String> providers = manager.getProviders( true );
manager.requestLocationUpdates( “gps”,
TIME_PERIOD,
MIN_DISTANCE_MOVED,
this );
manager.removeUpdates( this );
public void onLocationChanged( Location location ) {
double latitude = location.getLatitude();
}
Sensors – How to access them in code?
31
Returns subset of {“gps”,
“network”, “passive” }
Sampling Rate
(0 for max frequency)
Listener for location changes
Sensors – Note about Location APIs
32
Two APIs:
- Old API: LocationManager (Raw GPS)
- New API: LocationClient (Filtered location value fused with sensors)
For PA1, use the old API.
For Project work, use the new API.
Sensors – What rate to sample?
33
- Depends on event frequency (Eg: Walking, Occupancy)
- Power consideration (Eg: Accl 20 Hz v/s 1 Hz)
Android gotchas:
- Android delivers data at faster rate than specified
- Actual sampling rate can vary with time ( onSensorChanged() )
Sensors – Properties, Characteristics, Errors
34
1. Accuracy and Precision
2. Noise (Eg: Accl)
3. Drift (Eg: Gyro)
Sensors – Importance of understanding them
35
Example –
Integrating Accelerometer (m/sec2)  Velocity
v/s
Integrating Gyroscope (radian/sec)  Angle rotated
Very Noisy
Less noisy, but
drifts with time
Combine Accl + Gyro:
Sensor Fusion
Q: Can Accl be used to
get distance?
Sensors – Developing a good Sensor App
36
What sensors to use
Data Collection at required
sampling rate
Understand sensor
characteristics
Filtering, Signal Analysis,
Machine Learning, Calibration
Example: Developing a Walking Fitness app
Sensors – AngleApp
37
App that displays angle of the phone with the horizontal plane
- Calculates the angle between the gravity vector [0, 0, g] and
phone’s positive y-axis
Sensors – Different Co-ordinate axes
38
1. Phone co-ordinate axes (smartphone + tablet) – used by sensors
2. World co-ordinate axes
3. Screen (virtual world) co-ordinate axes
remapCoordinateSystem()
getRotationMatrix()
Questions?
Thank You!

More Related Content

What's hot

Role of java in android app development
Role of java in android app developmentRole of java in android app development
Role of java in android app developmentRahul Rana
 
Industrial Training in Android Application
Industrial Training in Android ApplicationIndustrial Training in Android Application
Industrial Training in Android ApplicationArcadian Learning
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from ScratchTaufan Erfiyanto
 
Introduction to android coding
Introduction to android codingIntroduction to android coding
Introduction to android codingHari Krishna
 
Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Ivo Neskovic
 
Intel ndk - a few Benchmarks
Intel ndk - a few BenchmarksIntel ndk - a few Benchmarks
Intel ndk - a few Benchmarksfirenze-gtug
 
Introduction to Android App Development
Introduction to Android App DevelopmentIntroduction to Android App Development
Introduction to Android App DevelopmentAndri Yadi
 
Android testing
Android testingAndroid testing
Android testingBitbar
 
Android seminar-report-body.doc
Android seminar-report-body.docAndroid seminar-report-body.doc
Android seminar-report-body.docDeepak Yadav
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentLiving Online
 
android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginnerAjailal Parackal
 
Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Svetlin Nakov
 
Apps development for Recon HUDs
Apps development for Recon HUDsApps development for Recon HUDs
Apps development for Recon HUDsXavier Hallade
 
Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorialilias ahmed
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overviewAhsanul Karim
 
Week 1 - Android Study Jams
Week 1 - Android Study JamsWeek 1 - Android Study Jams
Week 1 - Android Study JamsJoannaCamille2
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 

What's hot (20)

Role of java in android app development
Role of java in android app developmentRole of java in android app development
Role of java in android app development
 
Industrial Training in Android Application
Industrial Training in Android ApplicationIndustrial Training in Android Application
Industrial Training in Android Application
 
Android Development: Build Android App from Scratch
Android Development: Build Android App from ScratchAndroid Development: Build Android App from Scratch
Android Development: Build Android App from Scratch
 
Android Development Tutorial V3
Android Development Tutorial   V3Android Development Tutorial   V3
Android Development Tutorial V3
 
Introduction to android coding
Introduction to android codingIntroduction to android coding
Introduction to android coding
 
Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017Android - From Zero to Hero @ DEVit 2017
Android - From Zero to Hero @ DEVit 2017
 
Intel ndk - a few Benchmarks
Intel ndk - a few BenchmarksIntel ndk - a few Benchmarks
Intel ndk - a few Benchmarks
 
Introduction to Android App Development
Introduction to Android App DevelopmentIntroduction to Android App Development
Introduction to Android App Development
 
Android testing
Android testingAndroid testing
Android testing
 
Android seminar-report-body.doc
Android seminar-report-body.docAndroid seminar-report-body.doc
Android seminar-report-body.doc
 
Engineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) DevelopmentEngineering and Industrial Mobile Application (APP) Development
Engineering and Industrial Mobile Application (APP) Development
 
android-tutorial-for-beginner
android-tutorial-for-beginnerandroid-tutorial-for-beginner
android-tutorial-for-beginner
 
Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021
 
Android report
Android reportAndroid report
Android report
 
Apps development for Recon HUDs
Apps development for Recon HUDsApps development for Recon HUDs
Apps development for Recon HUDs
 
Android development-tutorial
Android development-tutorialAndroid development-tutorial
Android development-tutorial
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
 
Week 1 - Android Study Jams
Week 1 - Android Study JamsWeek 1 - Android Study Jams
Week 1 - Android Study Jams
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 

Viewers also liked

Viewers also liked (11)

Changed
ChangedChanged
Changed
 
Research Essay on Living in Owen Sound
Research Essay on Living in Owen SoundResearch Essay on Living in Owen Sound
Research Essay on Living in Owen Sound
 
能力雜誌報導TCIT
能力雜誌報導TCIT能力雜誌報導TCIT
能力雜誌報導TCIT
 
cv (1)
cv (1)cv (1)
cv (1)
 
Mohawk College Research Essay
Mohawk College Research EssayMohawk College Research Essay
Mohawk College Research Essay
 
Web developers
Web developersWeb developers
Web developers
 
El Internet
El InternetEl Internet
El Internet
 
Web developers
Web developersWeb developers
Web developers
 
201520184
201520184201520184
201520184
 
Tari Remo Jawa Timur By Wanto Herwanto
Tari Remo Jawa Timur By Wanto HerwantoTari Remo Jawa Timur By Wanto Herwanto
Tari Remo Jawa Timur By Wanto Herwanto
 
Proj
ProjProj
Proj
 

Similar to Android tutorial1

Mobile application and Game development
Mobile application and Game developmentMobile application and Game development
Mobile application and Game developmentWomen In Digital
 
Android chapter02-setup1-sdk
Android chapter02-setup1-sdkAndroid chapter02-setup1-sdk
Android chapter02-setup1-sdkTran Le Hoan
 
Android studio
Android studioAndroid studio
Android studioAndri Yabu
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a NutshellAleix Solé
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorialDanish_k
 
Module-I_Introduction-to-Android.pptx
Module-I_Introduction-to-Android.pptxModule-I_Introduction-to-Android.pptx
Module-I_Introduction-to-Android.pptxlancelotlaytan1996
 
Introduction To Android For Beginners.
Introduction To Android For Beginners.Introduction To Android For Beginners.
Introduction To Android For Beginners.Sandeep Londhe
 
Android installation guide
Android installation guideAndroid installation guide
Android installation guidemagicshui
 
Android tutorial ppt
Android tutorial pptAndroid tutorial ppt
Android tutorial pptRehna Renu
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
androidPramming.ppt
androidPramming.pptandroidPramming.ppt
androidPramming.pptBijayKc16
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentAhsanul Karim
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answerskavinilavuG
 
Android best training-in-mumbai
Android best training-in-mumbaiAndroid best training-in-mumbai
Android best training-in-mumbaivibrantuser
 

Similar to Android tutorial1 (20)

Mobile application and Game development
Mobile application and Game developmentMobile application and Game development
Mobile application and Game development
 
Android chapter02-setup1-sdk
Android chapter02-setup1-sdkAndroid chapter02-setup1-sdk
Android chapter02-setup1-sdk
 
Android studio
Android studioAndroid studio
Android studio
 
Notes Unit2.pptx
Notes Unit2.pptxNotes Unit2.pptx
Notes Unit2.pptx
 
Android
AndroidAndroid
Android
 
Android Development in a Nutshell
Android Development in a NutshellAndroid Development in a Nutshell
Android Development in a Nutshell
 
Android
Android Android
Android
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Module-I_Introduction-to-Android.pptx
Module-I_Introduction-to-Android.pptxModule-I_Introduction-to-Android.pptx
Module-I_Introduction-to-Android.pptx
 
Introduction To Android For Beginners.
Introduction To Android For Beginners.Introduction To Android For Beginners.
Introduction To Android For Beginners.
 
Android installation guide
Android installation guideAndroid installation guide
Android installation guide
 
Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Android tutorial ppt
Android tutorial pptAndroid tutorial ppt
Android tutorial ppt
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
androidPramming.ppt
androidPramming.pptandroidPramming.ppt
androidPramming.ppt
 
Synapseindia android apps application
Synapseindia android apps applicationSynapseindia android apps application
Synapseindia android apps application
 
Day: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application DevelopmentDay: 2 Environment Setup for Android Application Development
Day: 2 Environment Setup for Android Application Development
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answers
 
Android best training-in-mumbai
Android best training-in-mumbaiAndroid best training-in-mumbai
Android best training-in-mumbai
 

Recently uploaded

Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857delhimodel235
 
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi NcrSapana Sha
 
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiFULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiMalviyaNagarCallGirl
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineShivna Prakashan
 
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Servicedoor45step
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | DelhiMalviyaNagarCallGirl
 
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Service
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts ServiceIndian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Service
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Servicedoor45step
 
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Servicedoor45step
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Benjamin Portfolio Process Work Slideshow
Benjamin Portfolio Process Work SlideshowBenjamin Portfolio Process Work Slideshow
Benjamin Portfolio Process Work Slideshowssuser971f6c
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000Sapana Sha
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiMalviyaNagarCallGirl
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Parkjosebenzaquen
 
Roadrunner Lodge, Motel/Residence, Tucumcari NM
Roadrunner Lodge, Motel/Residence, Tucumcari NMRoadrunner Lodge, Motel/Residence, Tucumcari NM
Roadrunner Lodge, Motel/Residence, Tucumcari NMroute66connected
 
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call GirlsFaridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
San Jon Motel, Motel/Residence, San Jon NM
San Jon Motel, Motel/Residence, San Jon NMSan Jon Motel, Motel/Residence, San Jon NM
San Jon Motel, Motel/Residence, San Jon NMroute66connected
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiMalviyaNagarCallGirl
 

Recently uploaded (20)

Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
 
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
9654467111 Full Enjoy @24/7 Call Girls In Saket Delhi Ncr
 
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | DelhiFULL ENJOY - 9953040155 Call Girls in Noida | Delhi
FULL ENJOY - 9953040155 Call Girls in Noida | Delhi
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
 
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 39 Noida✨8375860717⚡Escorts Service
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
 
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | DelhiFULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | Delhi
FULL ENJOY - 9953040155 Call Girls in New Ashok Nagar | Delhi
 
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Service
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts ServiceIndian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Service
Indian High Profile Call Girls In Sector 18 Noida 8375860717 Escorts Service
 
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts ServiceRussian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
Russian⚡ Call Girls In Sector 104 Noida✨8375860717⚡Escorts Service
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
 
Benjamin Portfolio Process Work Slideshow
Benjamin Portfolio Process Work SlideshowBenjamin Portfolio Process Work Slideshow
Benjamin Portfolio Process Work Slideshow
 
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 60009654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
9654467111 Call Girls In Noida Sector 62 Short 1500 Night 6000
 
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Gandhi Vihar | Delhi
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Park
 
Roadrunner Lodge, Motel/Residence, Tucumcari NM
Roadrunner Lodge, Motel/Residence, Tucumcari NMRoadrunner Lodge, Motel/Residence, Tucumcari NM
Roadrunner Lodge, Motel/Residence, Tucumcari NM
 
call girls in Noida New Ashok Nagar 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Noida New Ashok Nagar 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Noida New Ashok Nagar 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Noida New Ashok Nagar 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
 
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call GirlsFaridabad Call Girls : ☎ 8527673949, Low rate Call Girls
Faridabad Call Girls : ☎ 8527673949, Low rate Call Girls
 
San Jon Motel, Motel/Residence, San Jon NM
San Jon Motel, Motel/Residence, San Jon NMSan Jon Motel, Motel/Residence, San Jon NM
San Jon Motel, Motel/Residence, San Jon NM
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
 
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | DelhiFULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
FULL ENJOY - 9953040155 Call Girls in Mahipalpur | Delhi
 

Android tutorial1

  • 1. TUTORIAL 1 Kartik Sankaran kar.kbc@gmail.com CS4222 Wireless and Sensor Networks [2nd Semester 2013-14] 20th January 2014 Android Concepts and Programming
  • 2. PART 1: Introduction to Android - Simple Android Apps: HelloWorldApp and ButtonApp PART 2: Introduction to Sensors - Simple Sensor App: AngleApp Goal of the Tutorials: - Help you quickly get started with Android programming. - Cover concepts not explained well on the Android website. Agenda 2
  • 3. What is Android? - Linux-based Operating System for mobile devices - Developed by Android, Inc. (later purchased by Google) - First Android phone in October 2008 - Multiple companies producing Android phones: Samsung, HTC, LG, Motorola, ASUS, and many others Introduction to Android 3
  • 4. Android is not just “Linux ported to mobile phones” - Linux code: < 500 MB - Android code: > 10 GB Why Linux? - Process management - Security - Code can be forked Introduction to Android 4
  • 5. Android Version History: (most phones run Jelly Bean) Introduction to Android 5
  • 6. Typical specs: - 1 GB RAM, 16 GB flash storage, 1 GHz multi-core processor, GPU - Have variety of sensors! - Limited battery : approx 2000 mAh Mobiles have limited memory (not anymore!): - Android can kill an App taking too much memory - Each App has an upper limit on heap space: 32 MB on Galaxy Nexus Major battery drainers: - Display, Processor, 3G, GPS Introduction to Android 6
  • 7. How does Android manage Applications? - Multiple applications can run at same time - Only one instance of an App runs at a time - Typical buttons: Home, Back, Menu, Search Home button: Similar to minimizing a window (state retained) Back button: Similar to closing a window (state destroyed) - After App destroyed, its still in memory! Introduction to Android 7
  • 8. How to write Applications? - Apps are mostly written in Java. - Compiled to Dalvik (dex) code. (Dalvik is a village in Iceland) Each App runs: - On Dalvik VM - Separate process - Separate User ID (for security) Why Dalvik? - Memory Optimized (Jar 113 KB  Dex 20 KB) - Avoid paying money to Sun (Oracle) Why not directly convert Java  Dex? - Use 3rd party Java libraries Introduction to Android 8 (Image from Marakana’s slides on Android Internals)
  • 9. Installation Steps: 1. Install Java (Version 6 or above) 2. Install Android SDK - http://developer.android.com/sdk/index.html Your first Android program 9 If any problem, then email/meet me
  • 10. Installation Steps: 3. Install Android ‘APIs’ (needs a good internet connection, takes a while) - http://developer.android.com/sdk/installing/adding-packages.html - SDK Manager.exe (at root of SDK installation folder) - API 17 + SDK tools + SDK platform tools are needed Your first Android program 10
  • 11. Installation Steps: 4. Install an IDE of your choice a. Eclipse - ADT Bundle has Android SDK + Eclipse IDE + ADT Plugin http://developer.android.com/sdk/index.html - If you already have Eclipse (>= 3.6.2 Helios), install the ADT plugin: http://developer.android.com/sdk/installing/installing-adt.html Your first Android program 11
  • 12. Installation Steps: 4. Install an IDE of your choice b. IntelliJ (approx 120 MB) - http://www.jetbrains.com/idea/download/index.html c. Emacs (or any text editor of your choice) Your first Android program 12
  • 13. Installation Steps: 5. Install phone’s device drivers (Mac users skip this step) a. Windows - http://developer.android.com/tools/extras/oem-usb.html - http://www.samsung.com/us/support/owners/product/SCH-I515MSAVZW b. Linux (/etc/udev/rules.d/51-android.rules) - http://developer.android.com/tools/device.html - SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev" Your first Android program 13
  • 14. Creating an Android project: 1. Using command line $ android list targets (to get target IDs) $ android create project --target 9 --name HelloWorld --path ./HelloWorld --activity HelloWorldActivity --package nus.cs4222.helloworld 2. Using an IDE - File New Project - Fill in the details, similar to above Your first Android program 14
  • 15. Project Structure: src: Your source code res/layout/main.xml: Your GUI libs: Library jars In Android, the GUI screen is called an ‘Activity’ (will be covered in detail in next tutorial) Your first Android program 15
  • 16. res/layout/main.xml : (already created by default) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World!" /> </LinearLayout> Your first Android program 16
  • 17. HelloWorldActivity.java : (already created by default) public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); // Specify what GUI to use (res/layout/main.xml) // ‘R’ stands for ‘Resources’ setContentView( R.layout.main ); } } Your first Android program 17
  • 18. Turn on USB debugging on the phone: Settings  Developer Options Enable USB Debugging Make sure you installed the USB Driver for this phone! (in this case, Samsung Galaxy Nexus) 18
  • 19. Build (compile) your App: 1. Using command line: $ ant debug 2. Using an IDE: ‘Build’ button/menu - App: bin/HelloWorld-debug.apk Install App on phone: 1. Using command line: $ adb install -r bin/HelloWorld-debug.apk 2. Using an IDE: ‘Install/Run’ button/menu 19
  • 20. Debugging (use the filter field most of the time): Monitor.bat (AKA ddms.bat) 20
  • 21. Adding more GUI ‘widgets’: - EditText: User can enter text here - Button: Pressing it triggers an action - TextView: Displays some text Your first Android program 21 1. Enter text here 2. Press the button 3. Text gets appended here
  • 22. res/layout/main.xml : (add Button and EditText widgets) <LinearLayout ...> <EditText android:id="@+id/EditText_Message" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="" /> <Button android:id="@+id/Button_Send" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send Message" /> <TextView android:id="@+id/TextView_Message" ... /> </LinearLayout> Your first Android program 22 GUI layout defined using XML Widgets have IDs “@” Referring to a resource “+” Adds this ID to the R class
  • 23. HelloWorldActivity.java : public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ public void onCreate( Bundle savedInstanceState ) { ... } // Text View (displays messages) private TextView textView_Message; // Edit Text (user enters message here) private EditText editText_Message; // Button to trigger an action private Button button_Send; } Your first Android program 23 GUI widgets in Java code
  • 24. HelloWorldActivity.java : public class HelloWorldActivity extends Activity { /** Called when the activity is first created. */ public void onCreate( Bundle savedInstanceState ) { ... // Get references to the GUI widgets textView_Message = (TextView) findViewById( R.id.TextView_Message ); editText_Message = (EditText) findViewById( R.id.EditText_Message ); button_Send = (Button) findViewById( R.id.Button_Send ); } } Your first Android program 24
  • 25. HelloWorldActivity.java : public void onCreate( Bundle savedInstanceState ) { ... // Set the button's click listener button_Send.setOnClickListener( new View.OnClickListener() { public void onClick( View v ) { // Change the text view String newText = textView_Message.getText() + "n New Message: " + editText_Message.getText(); textView_Message.setText ( newText ); } } ); } Your first Android program 25
  • 26. Android online tutorials: http://developer.android.com/guide/components/fundamentals.html http://developer.android.com/training/basics/firstapp/index.html Note: Many Android programmers directly jump into coding. However, it is more important to understand the concepts first before writing complex Apps. Otherwise, coding becomes a messy headache. Your first Android program 26
  • 27. Break
  • 28. 1. What sensors are available? What do they sense? 2. How to access sensor data in Android? 3. What are the sensor properties and characteristics? 4. Why is it important to understand each sensor’s properties? 5. Simple Sensor App: AngleApp Introduction to Sensors 28
  • 29. Sensors – What do they sense? 29 http://www.youtube.com/watch?v=C7JQ7Rpwn2k Understanding the physics behind the sensors 1. Motion Sensors - Accelerometer (also: Gravity, Linear Accl) - Gyroscope - Rotation Vector 2. Position Sensors - Magnetic Field - Orientation - Proximity 3. Environmental Sensors - Temperature, Light, Pressure, Humidity 4. Others - GPS, Camera, Microphone, Network These sensors have different APIs May be physical or virtual
  • 30. SensorManager manager = (SensorManager) getSystemService( Context.SENSOR_SERVICE ); Sensor light = manager.getDefaultSensor( Sensor.TYPE_LIGHT ); protected void onResume() { manager.registerListener( this, light, SensorManager.SENSOR_DELAY_NORMAL); } protected void onPause() { manager.unregisterListener( this ); } public void onSensorChanged( SensorEvent event ) { float lux = event.values[0]; } Sensors – How to access them in code? 30 Returns null if sensor not present Sampling Rate Listener for sensor changesWhy float and not double?
  • 31. LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE ); List <String> providers = manager.getProviders( true ); manager.requestLocationUpdates( “gps”, TIME_PERIOD, MIN_DISTANCE_MOVED, this ); manager.removeUpdates( this ); public void onLocationChanged( Location location ) { double latitude = location.getLatitude(); } Sensors – How to access them in code? 31 Returns subset of {“gps”, “network”, “passive” } Sampling Rate (0 for max frequency) Listener for location changes
  • 32. Sensors – Note about Location APIs 32 Two APIs: - Old API: LocationManager (Raw GPS) - New API: LocationClient (Filtered location value fused with sensors) For PA1, use the old API. For Project work, use the new API.
  • 33. Sensors – What rate to sample? 33 - Depends on event frequency (Eg: Walking, Occupancy) - Power consideration (Eg: Accl 20 Hz v/s 1 Hz) Android gotchas: - Android delivers data at faster rate than specified - Actual sampling rate can vary with time ( onSensorChanged() )
  • 34. Sensors – Properties, Characteristics, Errors 34 1. Accuracy and Precision 2. Noise (Eg: Accl) 3. Drift (Eg: Gyro)
  • 35. Sensors – Importance of understanding them 35 Example – Integrating Accelerometer (m/sec2)  Velocity v/s Integrating Gyroscope (radian/sec)  Angle rotated Very Noisy Less noisy, but drifts with time Combine Accl + Gyro: Sensor Fusion Q: Can Accl be used to get distance?
  • 36. Sensors – Developing a good Sensor App 36 What sensors to use Data Collection at required sampling rate Understand sensor characteristics Filtering, Signal Analysis, Machine Learning, Calibration Example: Developing a Walking Fitness app
  • 37. Sensors – AngleApp 37 App that displays angle of the phone with the horizontal plane - Calculates the angle between the gravity vector [0, 0, g] and phone’s positive y-axis
  • 38. Sensors – Different Co-ordinate axes 38 1. Phone co-ordinate axes (smartphone + tablet) – used by sensors 2. World co-ordinate axes 3. Screen (virtual world) co-ordinate axes remapCoordinateSystem() getRotationMatrix()