Presentation Android

53
Introduction à Android by Jean Collas, Ghislain Deffrasne, Reda Sebbani is licensed under a Creative Commons Attribution 2.0 France License . Original at http://www.jean-collas.fr/android

description

Présentation & Introduction à Android - Nouveau système d'exploitation mobile lancé par Google.

Transcript of Presentation Android

Page 1: Presentation Android

Introduction à Android by Jean Collas, Ghislain Deffrasne, Reda Sebbani is licensed

under a Creative Commons Attribution 2.0 France License. Original at http://www.jean-collas.fr/android

Page 2: Presentation Android

Ouverture

Jean Collas, Réda Sebbani, Ghislain Deffrasnes

Page 3: Presentation Android

ContexteContexte

Téléphonie Mobile : Smart Phone

40 millions de smartphones / trimestre (2008)

Chiffre d’affaire énorme

Développement logiciel pour mobiles

iPhone OS

Windows Mobile

RIM

Symbian

Page 4: Presentation Android

Contexte Concurrentiel

0%

10%

20%

30%

40%

50%

60%

70%

2007

2008

Systèmes d’exploitation pour Smart phone :

Marché en constante augmentation (+28% en 1 an, 31M -> 40M)Possibilités d’évolution énormes avec un bon produit

Page 5: Presentation Android

Internet & Google

Fondé en 98, croissance constante

Attaque du monde mobile par la source : le système d’exploitation Android

Politique de financement par la publicité

Multiples domaines de l’informatique :Recherche, cartographie, vidéo, conception 3D, suite bureautique, publicité, navigateur, …

Page 6: Presentation Android

Points forts d’AndroidPoints fort d’Android

Point de vue constructeur

Système Linux + Java

Point de vue utilisateur

Système fonctionnel, intuitif, évolutif

Point de vue développeur

Application développées en syntaxe Java

SDK complet fourni

Point de vue bidouilleur

Projet Open Source C++ / Java

Page 7: Presentation Android

Start-up AndroidAoût 2005

Android MarketAoût 2008

Android 1.0 et SDK release 1 Septembre 2008

T-Mobile G1

Android : Open SourceOctobre 2008

Avril 2008

DeveloperChallenge

Novembre 2007Annonce d’Android

Open Handset Alliance

SDK pour Android

Développementd’Android

Android 1.0 et SDK release 2 Novembre 2008

Historique

Historique

Page 8: Presentation Android

Consortium créé fin 2007

Open Handset Alliance

Entreprises de commercialisationFabricants d'appareils mobiles

Opérateurs de téléphonie mobileFabricants de semi-conducteurs

Fabricants de logiciels

47 compagnies

But : développer des normes ouvertes pour les appareils de téléphonie mobile

Page 9: Presentation Android

T-Mobile G1

1er téléphone avec Android

De 180 à 400 $

Wi-fi et Bluetooth

GPS

Accéléromètres

Caméra

Écran tactile

T-Mobile G1 (HTC)

Page 10: Presentation Android

LG

L’agora par Kogan

De nouveaux mobiles

Page 11: Presentation Android

Preuve de sa portabilité – Futur d’Android

Et si Android n’était pas seulement conçu pour les smartphone?

Android sur un NetBook

Page 12: Presentation Android

Barre de recherche « Google Search »

Gmail

Google Talk (IM)

Navigateur Web

Gmaps

Google StreetView

Intégration des applications Google

Page 13: Presentation Android

Google Maps

Orientation

AchatsCovoiturage

Travail

Tourisme

Voyage

VoisinageGéolocalisation

Géolocalisation

Exemples d’applications : Android Market

Page 14: Presentation Android

Points d’accès d’Android

Point de vue constructeur

Système Linux + Java

Point de vue utilisateur

Système fonctionnel, intuitif, évolutif

Point de vue développeur

Application développées en syntaxe Java

SDK complet fourni

Point de vue bidouilleur

Projet Open Source C++ / Java

Page 15: Presentation Android

ANDROID RUNTIME

APPLICATION FRAMEWORK

APPLICATIONS

LINUX KERNEL

Core Libraries

Dalvik Virtual Machine

LIBRARIESSurface Manager Media Framework SQL Lite

OpenGL Audio Manager WebKit

SGL SSL Libc

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

Activity Manager Window Manager Content Providers View System

Package Manager

TelephonyManager

Resource Manager

Location Manager

Notification Manager

Home Contacts Phone Browser …

Architecture

JNI

Page 16: Presentation Android

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

Noyau d’Android

HARDWARE ABSTRACTION LAYERGraphics Audio Camera Bluetooth GPS WiFi …

Architecture ARMBasé sur Linux 2.6.24

Système de fichiers supporté : FAT32Support de TCP/IP, UDP,…

Page 17: Presentation Android

Adaptation aux besoins du mobile

• Alarm : timers pour « réveiller » des périphériques• Ashmem : partage de mémoire entre processus• Binder : driver IPC pour la communication inter-processus• Power Management• Low Memory Killer• Kernel Debugger• Logger

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

HARDWARE ABSTRACTION LAYERGraphics Audio Camera Bluetooth GPS WiFi …

Page 18: Presentation Android

Librairies

LIBRARIESSurface Manager Media Framework SQL Lite

OpenGL Audio Manager WebKit

SGL SSL Libc

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

Page 19: Presentation Android

Application 1

Application 2

Surface Manager

Surface Flinger

Écran(Frame Buffer)

Page 20: Presentation Android

Audio Manager

Audio Flinger

OreilletteSonnerie d’appel

Lecteur MP3 Écouteurs

Page 21: Presentation Android

ANDROID RUNTIME

Core Libraries

Dalvik Virtual Machine

Machine Virtuelle Dalvik

LIBRARIESSurface Manager Media Framework SQL Lite

OpenGL Audio Manager WebKit

SGL SSL Libc

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

Page 22: Presentation Android

Machine Virtuelle Dalvik

Exécute des fichiers .dex (Dalvik Executable)

Nouvelle instance pour chaque processus : Applications indépendantes

Dalvik core class library fournit une base de développement proche de java SE, adapté au mobile

Page 23: Presentation Android

ANDROID RUNTIME

Core Libraries

Dalvik Virtual Machine

LIBRARIESSurface Manager Media Framework SQL Lite

OpenGL Audio Manager WebKit

SGL SSL Libc

Framework & fondations des applications

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

APPLICATION FRAMEWORK

JNI

Activity Manager Window Manager Content Providers View System

Package Manager

TelephonyManager

Resource Manager

Location Manager

Notification Manager

Page 24: Presentation Android

Décrit par : Une action (VIEW, EDIT, MAIN,…) La donnée à traiter (sous forme d’URI)

Intents

Intent : Requête; Description d’une action à effectuer Fait le lien entre différentes applications

Types d’Intent : Explicite (référence exacte) Implicite (description)

Page 25: Presentation Android

Intents

Intent 1 App.AIntent 2 App.B

.

.

Messagerie Contacts

StartActivity(View Contact)

Intent Resolver

Echange

Publication

IntentFilterVIEWEDIT

12

3

Edit ContactContactsView Contact Contacts

Page 26: Presentation Android

Intent Filter

<intent-filter>

<action android:value="android.intent.action.VIEW" />

<action android:value="android.intent.action.EDIT" />

<action android:value="android.intent.action.PICK" />

<category android:value="android.intent.category.DEFAULT" />

<type

android:value="vnd.android.cursor.dir/vnd.google.contact" />

</intent-filter>

Objectif : Description du handler

IntentFilter décrivent les capacités de l’application.

Publication d’IntentFilters par les activités

Page 27: Presentation Android

void startActivity(Intent intent) ;void sendBroadcast(Intent intent)boolean bindService(Intent service, int flags)ComponentName startService(Intent service)

Les URIs - Utilisation

125people///contacts/content:

&cbp=1,yaw,,pitch,zoom

Exemples d’URI:

25,32geo:VIEW_ACTION

Intent

EDIT_ACTION

CALL_ACTION

Ouvre l’application de géo-localisation à la position donnée (latitude, longitude).

123tel: Appelle le numéro 123

VIEW_ACTION cbll=25,32google.streetview:

Page 28: Presentation Android

Notification Manager

Applications peuvent s’exécuter simultanément

Différentes formes de notifications :- LED- Son- Vibreur- Barre de notification (icône)

Notifications d’événements du background

Barre de notifications

Mise en place facilité par le Notification Manager

Page 29: Presentation Android

Composants d’une application

Activity

ServiceContent Provider

Broadcast Receiver

Page 30: Presentation Android

SYSTEMAPK APK

Remotedata

SQLiteData

XML

Activity Activity serviceActivity

Content Provider

service

Page 31: Presentation Android

SYSTEMAPK APK

Remotedata

SQLiteData

XML

Activity Activity serviceActivity

Content Provider

service

ContentProvider

Page 32: Presentation Android

Les URIs

Activity

ServiceContent Provider

IntentReceiver

Exemples d’URI d’un content provider:

0 ou plusieurs segments, permettent de déterminer le type de données C

Enregistrement spécifique éventuellement demandé (identifiant, référence)D

Préfixe d’accès aux données, type d’URIA

Identifiant ou type du content provider à consulterB

125people///contacts/content:

53users///com.maCompanie.monApp/content:

<provider class=".NotePadProvider"android:authorities="com.google.provider.NotePad" />

Page 33: Presentation Android

Content Provider

Content Providers

Activity

ServiceContent Provider

IntentReceiver

Contacts

Browser

MediaStore.Images

MediaStore.Audio

Settings

Applications

Lecteur MP3

URI

Annuaire

Résultat

ContentResolver+ delete()+ insert()+ notifyChange()+ query()+ update()

//contacts/ 125people/content:URI :

Page 34: Presentation Android

Activity

Activity

ServiceContent Provider

IntentReceiverObjet qui possède un cycle de vie

Généralement, une Activity affiche une UI

Point d’entrée d’une application

Code qui réalise un traitement

<activity class=".NoteEditor" android:label="@string/title_note">

<intent-filter android:label="@string/resolve_edit">

<action android:value="android.intent.action.VIEW" />

<action android:value="android.intent.action.EDIT" />

<category android:value="android.intent.category.DEFAULT" />

<type android:value="vnd.android.cursor.item/vnd.google.note" />

</intent-filter>

</activity>

Page 35: Presentation Android

Broadcast receiver

Activity

ServiceContent Provider

Broadcast

Receiver

.

Broadcast receiver permet de réagir à des évènements extérieurs à l’application

Permet également de réagir à des notification du système (évènements extérieurs/matériels).

Un Intent peut être boadcasté; on peut utiliser un broadcast receiver pour gérer ce type d’evt

Permet de réveiller une application

<receiver android:name=".app.OneShotAlarm" android:process=":remote" />

Page 36: Presentation Android

Service

Activity

ServiceContent Provider

IntentReceiver

Composante sans GUIActivité de longue durée

Service interne : Context.startService()Service externe : Context.bindService()

Communication via une interfaceEx Media Player : pause, lecture, stop, etc

Page 37: Presentation Android

<service android:name=".app.RemoteService" android:process=":remote">

<intent-filter>

<!-- These are the interfaces supported by the service, which

you can bind to. -->

<action android:name="com.example.android.apis.app.IRemoteService" />

<!-- This is an action code you can use to select the service

without explicitly supplying the implementation class. -->

<action android:name="com.example.android.apis.app.REMOTE_SERVICE" />

</intent-filter>

</service>

Service : AndroidManifest

Activity

ServiceContent Provider

IntentReceiver

Page 38: Presentation Android

AndroidManifest complet

Activity

IntentReceiver

Service

Content Provider

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.android.notepad">

<application android:icon="@drawable/app_notes" android:label="@string/app_name">

<activity class=".NotesList" android:label="@string/title_notes_list">

<intent-filter>

<action android:value="android.intent.action.MAIN" />

<category android:value="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<provider class=".NotePadProvider" android:authorities="com.google.provider.NotePad"/>

<service android:name=".app.RemoteService" android:process=":remote">

<intent-filter>

<action android:name="com.example.android.apis.app.IRemoteService" />

</intent-filter>

</service>

<receiver android:name=".app.OneShotAlarm" android:process=":remote" />

</application>

</manifest>

Page 39: Presentation Android

OnCreate() Allocation des ressources

OnStart() Affichage à l’écran

OnResume() Passage au premier plan

OnPause() Passage en arrière plan

OnStop() Arrêt de l’exécution

OnDestroy() Libération des ressources

Cycle de vie d’une Activité

Activity

ServiceContent Provider

IntentReceiver

Running

Paused

Stopped

Killed

Page 40: Presentation Android

Cycle de vie d’une Activité

New Activity

Running(Foreground)

1. OnCreate()2. OnStart()3. OnResume()

Paused(Background)

OnFreeze()OnPause()

OnResume()

Destroyed

OnDestroy()

3. OnResume()2. OnStart()1. OnRestart()

ApplicationKilled

Retour à l’application

Stopped(Plus visible)

OnStop()Application plus visible

L’utilisateur quitte

Besoin de mémoire

Page 41: Presentation Android

Hiérarchie des processus

Empty Process

Background Process

Service Process

Visible Process

Foreground Process

Imp

ort

ance

Cache pour les processus

Processus en arrière plan, non visible.

Processus des composants « Service » disponibles en arrière plan

Activité en arrière plan

Activité

Hiérarchie des processus

Page 42: Presentation Android

ANDROID RUNTIME

Core Libraries

Dalvik Virtual Machine

LIBRARIESSurface Manager Media Framework SQL Lite

OpenGL Audio Manager WebKit

SGL SSL Libc

Les applications

LINUX KERNEL

Display Driver

Keypad Driver

Camera Driver

WiFi Driver

Flash Memory Driver

Audio Driver

Binder (IPC) Driver

Power Management

APPLICATION FRAMEWORK

JNI

Activity Manager Window Manager Content Providers View System

Package Manager

TelephonyManager

Resource Manager

Location Manager

Notification Manager

APPLICATIONS

Home Contacts Phone Browser …

Page 43: Presentation Android

package com.android.hello;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class HelloAndroid extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView tv = new TextView(this);

tv.setText("Hello, Android");

setContentView(tv);

}

}

JAVA(uniquement)

1 champ de texte

HelloAndroid.java

Développement en Java : Méthode classique

Page 44: Presentation Android

JAVAmétier

XML vues

package com.android.hello;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class HelloAndroid extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}

HelloAndroid.java

<?xml version="1.0" encoding="utf-8"?>

<TextView

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:text="@string/hello"/> main.xml

Séparation Présentation / Métier

Page 45: Presentation Android

package com.android.hello;

public final class R {

public static final class attr {

}

public static final class drawable {

public static final int icon=0x7f020000;

}

public static final class layout {

public static final int main=0x7f030000;

}

public static final class string {

public static final int app_name=0x7f040001;

public static final int hello=0x7f040000;

}

}

main.xmlDescription du layout

strings.xml

icon.png

Étiquettes Texte

Image

Description du layoutR.java

Interfaçage des ressources

Génération automatique

Page 46: Presentation Android

.java .class

Sources

.png

.xml

Ressources + Manifest

.dex

.apk

Byte-code (optimisé)

Application compilée

Compilation et Déploiement d’une Application

/data/app/

Page 47: Presentation Android

HelloWorld

Page 48: Presentation Android

Vidéos StreetView + Compass

Page 49: Presentation Android

Vidéos StreetView + Compass

?

Page 50: Presentation Android
Page 51: Presentation Android

Vidéo StreetView + Compass

Page 52: Presentation Android

Vidéo StreetView + Compass

Page 53: Presentation Android

Booter Android