Download - SESTINFO 2011 Apresentacao Android
![Page 1: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/1.jpg)
Desenvolvimento na PlataformaGoogle Android
SESTINFO 2011 Universidade Metodista de São Paulo
Rafael Sakurai
RodrigoCascarrolho
1
![Page 2: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/2.jpg)
Agenda
• Introdução ao Android, arquitetura e ambiente de desenvolvimento.
• Activity
• Intent e Intent Filter
• View
• Service
• Broadcast Receiver
• Content Provider
• GPS e Mapas
• Android Market
2
![Page 3: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/3.jpg)
O que é Android?• Sistema Operacional
• Middleware
• Aplicativos
• Interface
• Android SDK
• Apache License, Version 2.0
• Open Source
3
![Page 4: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/4.jpg)
Arquitetura
4
![Page 5: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/5.jpg)
Quem apoia Android?
• Open Handset Alliance
• Google Inc.
5
![Page 6: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/6.jpg)
Alguns números
• 100 milhões de dispositivos com Android.
• ~ 400 mil novas ativações de dispositivos com Android por dia.
• 200 mil aplicações no Android Market.
• Mais de 320 dispositivos que utilizam Android.
• 4.5 bilhões de aplicações baixadas do Android Market.
Números divulgados no Google IO 2011 - http://www.google.com/events/io/2011/index-live.html
6
![Page 7: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/7.jpg)
Versões Android
http://developer.android.com/resources/dashboard/platform-versions.html
7
![Page 8: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/8.jpg)
Versões Android
• Curiosidade - o codenome das versões são nomes de doces:
• 1.5 - Cupcake
• 1.6 - Donut
• 2.1 - Eclair
• 2.2 - Froyo
• 2.3 - Gingerbread
• 3.0 - Honeycomb
• 3.1 - Ice-cream sandwich
8
![Page 9: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/9.jpg)
Ambiente de Desenvolvimento• Java Developer Kit (JDK) - www.oracle.com/
technetwork/java/javase/downloads/index.html
• Eclipse IDE for Java Developers - www.eclipse.org
• Android SDK - http://developer.android.com/sdk/index.html
• ADT Plugin for Eclipse - http://developer.android.com/sdk/eclipse-adt.html
9
![Page 10: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/10.jpg)
Android SDK e AVD Manager• Clique no menu ou no menu Window →
Android SDK e AVD Manager.
10
![Page 11: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/11.jpg)
Emulador
• Iniciar emulador.
• Opções do emulador no Eclipse
• Enviar SMS
11
![Page 12: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/12.jpg)
Componentes de uma aplicação no Android
• Activity
• Intent e Intent Filters
• Services
• Broadcast Receivers
• Content Provider
12
![Page 13: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/13.jpg)
Activity
• Classe define qual a tela (View) irá representar e controla os eventos dela.
• Precisa ser uma classe filha de android.app.Activity.
• Deve implementar o método public void onCreate(Bundle savedInstanceState) {...} que inicializa os elementos da tela.
13
![Page 14: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/14.jpg)
Hello World++• Criando um projeto Android no Eclipse:
• No menu Arquivo selecione Novo → Outro → Android → Android Project.
• Defina os seguintes campos:
• Project Name: Sestinfo-HelloWorldPlus
• Informe onde deve ser salvo o projeto.
• Build Target: Google APIs - 2.1-update Level 7 ou Android 2.1-update1
• Application Name: SESTINFO 2011 - HelloWorldPlus
• Package name: br.metodista.sestinfo.helloworld
• Create Activity: HelloWorld
• Clique em Finalizar
14
![Page 15: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/15.jpg)
Hello World++
• Estrutura do Projeto
• src - Código fonte do projeto.
• gen - R.java - constantes que permitem acessar os elementos da tela.
• res - Recursos
• drawable... - imagens de acordo com o tamanho da tela.
• layout - arquivos xml com o layout da tela.
• values - arquivo xml com todos os textos.
• AndroidManifest.xml - configuração do projeto.
15
![Page 16: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/16.jpg)
Hello World++
• Layout gráfico do main.xml
16
![Page 17: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/17.jpg)
Hello World++
• Conteúdo inicial do arquivo main.xml
<?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:id="@+id/textView1" android:text="@string/hello" android:layout_height="wrap_content"></TextView></LinearLayout>
17
![Page 18: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/18.jpg)
Hello World++
• Adicionando mais componentes na tela:<?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" android:gravity="center" >
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:gravity="center" />
<LinearLayout android:layout_height="100dip" android:gravity="bottom" android:id="@+id/linearLayout1" android:layout_width="fill_parent" />
<Button android:id="@+id/btnVer" android:layout_width="fill_parent" android:layout_height="70dip" android:text="@string/mostrar" />
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/logoMeto" android:src="@drawable/logo_portal" />
</LinearLayout>
18
![Page 19: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/19.jpg)
Hello World++• Edite o arquivo values/strings.xml com os
seguintes valores:
• hello - Mini-curso\nDesenvolvimento na plataforma Google Android
• appname - SestInfo 2011 - HelloWorldPlus
• mostrar - Mostrar mensagem...
• msg - Bem vindo à SESTINFO 2011
• Adicione a imagem logo_portal.jpg na pasta drawable-mdpi.
19
![Page 20: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/20.jpg)
Hello World++
20
![Page 21: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/21.jpg)
Hello World++• Adicionar a ação para o botão Mostrar mensagem...package br.metodista.sestinfo.helloworld;
import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.Toast;
public class HelloWorld extends Activity { private Button mostrar;
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mostrar = (Button) findViewById(R.id.btnVer); mostrar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getBaseContext(), R.string.msg, Toast.LENGTH_LONG).show(); } }); }}
21
![Page 22: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/22.jpg)
Hello World++• Para executar a aplicação, clique com o botão direito sobre
o nome do projeto e escolha o item Run As → Android Application.
22
![Page 23: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/23.jpg)
Intent e Intent Filter
• Intent é utilizando para enviar uma solicitação para o Android executar como por exemplo:
• Fazer uma ligação
• Enviar um SMS
• Abrir o browser
• Solicita a abertura de outra aplicação
• Intent Filter é utilizado para mapear a ação de um Intent.
23
![Page 24: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/24.jpg)
View
• A View é a classe que representa os elementos da tela, onde cada elemento da tela é uma subclasse da classe View.
• Todos os elementos da tela são escritos na forma de XML, exemplo:
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content"android:layout_height="wrap_content" android:minHeight="80dip"android:minWidth="80dip" android:clickable="true"
android:visibility="visible" android:background="#00000000" android:paddingLeft="20dip" android:paddingTop="20dip" android:paddingRight="20dip" android:paddingBottom="20dip"></ImageView>
24
![Page 25: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/25.jpg)
Elementos de Tela
25
![Page 26: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/26.jpg)
Exemplo View
26
![Page 27: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/27.jpg)
Service
• A classe Service é utilizada para criar um serviço que é executado em background.
• O processamento e gerenciamento de memória de uma Service é controlada pelo sistema operacional.
• Processos com tempo e duração indeterminado.
• Processos que irão demorar mais que 10 segundos.
• Como por exemplo: download e player de audio e video.
27
![Page 28: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/28.jpg)
Service
28
![Page 29: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/29.jpg)
Usando o SD Card
• Após iniciar o emulador, entre na visualização Window → Show View → Android → File Explorer.
Adicionar um arquivo no dispositivo.
Pegar um arquivo no dispositivo.
29
![Page 30: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/30.jpg)
Broadcast Receiver• A classe BroadcastReceiver é utilizada para
executar as solicitações feitas pelos Intent.
• Ela também é executada em background para não atrapalhar os usuário, podendo por exemplo acionar uma Service.
• Não é recomendado abrir uma Activity ou qualquer iteração com o usuário.
• Com o BroadcastReceiver podemos criar uma aplicação que ao receber um SMS já emite um aviso e apresenta ele na tela.
30
![Page 31: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/31.jpg)
Exemplo Broadcast Receiver
31
![Page 32: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/32.jpg)
Enviar SMS via plugin do Eclipse• Utilizando o plugin do Eclipse é fácil enviar um SMS
ou fazer uma chamada telefônica para o emulador.
• Entre na visualização Window → Show View → Android → Emulator Control, digite um número de telefone qualquer, a mensagem SMS e clique em Send.
32
![Page 33: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/33.jpg)
Content Provider
• A classe ContentProvider permite compartilhar informações para que qualquer outra aplicação possa utilizá-las.
• Por exemplo a aplicação do Facebook coloca a foto dos seus contatos de acordo com a foto que está no perfil do contato no Facebook.
• Disponibilizar seus percursos com o GPS para outra aplicação.
33
![Page 34: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/34.jpg)
GPS e Mapas
• Global Positioning System (GPS) permite você localizar a posição atual do seu aparelho no Globo Terrestre.
• Google Maps permite você utilizar os mapas disponibilizados pela Google para criação de aplicações.
34
![Page 35: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/35.jpg)
Exemplo Mapas
35
![Page 36: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/36.jpg)
Exemplo GPS e Mapas
36
![Page 37: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/37.jpg)
Mais recursos do Android• Banco de Dados (SQLite)
• HTTP
• Web Services
• Acelerômetro
• Multimídia video e câmera
• Efeitos de transição
• E muito mais
37
![Page 38: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/38.jpg)
Android Market
38
![Page 39: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/39.jpg)
Android Market - Minha Conta
39
![Page 40: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/40.jpg)
Publicando uma aplicação no Android Market• No site http://developer.android.com
• Acesse a opção Publish.
• Crie seu perfil de desenvolvedor.
• Pague a taxa de registro (US$25,00) com cartão de credito.
• Aceite os termos de contrato da Google.
• Aplicações paga 70% para o desenvolvedor e 30% para a Google.
40
![Page 41: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/41.jpg)
Publicando uma aplicação no Android Market
41
![Page 42: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/42.jpg)
Publicando uma aplicação no Android Market
42
![Page 43: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/43.jpg)
Referencias
• [LECHETA, Ricardo R.] Google Android: Aprenda a criar aplicações para dispositivos móveis com o Android SDK, 2 ed. - Editora Novatec - 2010
• [Lúcio Camilo, Michel Lourenço] Android para Desenvolvedores, Editora Brasport - 2009
• Android Developers - http://developer.android.com/index.html
• Android Market - http://market.android.com
43
![Page 44: SESTINFO 2011 Apresentacao Android](https://reader035.vdocuments.site/reader035/viewer/2022062513/556a3d26d8b42a4a1e8b4786/html5/thumbnails/44.jpg)
Obrigado!
Rafael [email protected]@rafaelsakuraiwww.universidadejava.com.br
Rodrigo [email protected]@rodrigocascawww.rdgc.com.br
44