Android Tutorial
Android Tutorial
TUTORIAL 1
Kartik Sankaran
kar.kbc@gmail.com
Agenda
PART 1: Introduction to Android
Introduction to Android
What is Android?
- Linux-based Operating System for mobile devices
Introduction to Android
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
4
Introduction to Android
Android Version History: (most phones run Jelly Bean)
Introduction to Android
Typical specs:
- 1 GB RAM, 16 GB flash storage, 1 GHz multi-core processor, GPU
Introduction to Android
How does Android manage Applications?
- Multiple applications can run at same time
Introduction to Android
How to write Applications?
- Apps are mostly written in Java.
Why Dalvik?
- Memory Optimized
(Jar 113 KB Dex 20 KB)
- 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
10
a. Eclipse
- ADT Bundle has Android SDK + Eclipse IDE + ADT Plugin
http://developer.android.com/sdk/index.html
11
12
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
-
2. Using an IDE
- File New Project
- Fill in the details, similar to above
14
an Activity
(will be covered in detail in
next tutorial)
15
}
}
17
18
2. Using an IDE:
Build button/menu
- App: bin/HelloWorld-debug.apk
Install App on phone:
2. Using an IDE:
Install/Run button/menu
19
20
21
<EditText android:id="@+id/EditText_Message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Widgets have IDs
@ Referring to a resource
+ Adds this ID to the R class
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>
}
GUI widgets in Java code
editText_Message =
(EditText) findViewById( R.id.EditText_Message );
button_Send =
...
// 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 );
}
} );
}
25
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.
26
Break
Introduction to Sensors
1. What sensors are available? What do they sense?
28
1. Motion Sensors
- Accelerometer (also: Gravity, Linear Accl)
- Gyroscope
- Rotation Vector
http://www.youtube.com/watch?v=C7JQ7Rpwn2k
2. Position Sensors
- Magnetic Field
- Orientation
- Proximity
3. Environmental Sensors
4. Others
- GPS, Camera, Microphone, Network
29
SensorManager.SENSOR_DELAY_NORMAL);
}
protected void onPause() {
Sampling Rate
manager.unregisterListener( this );
}
public void onSensorChanged( SensorEvent event ) {
float lux = event.values[0];
}
MIN_DISTANCE_MOVED,
this );
Sampling Rate
(0 for max frequency)
manager.removeUpdates( this );
public void onLocationChanged( Location location ) {
double latitude = location.getLatitude();
}
32
33
34
v/s
Very Noisy
35
Understand sensor
characteristics
36
Sensors AngleApp
App that displays angle of the phone with the horizontal plane
37
remapCoordinateSystem()
getRotationMatrix()
38
Questions?
Thank You!