Formation aimaf-android-part2

23
Android Training Part 2 RGUIG Saad - AIMAF Android 1 lundi 21 janvier 13

Transcript of Formation aimaf-android-part2

Page 1: Formation aimaf-android-part2

Android Training Part 2

RGUIG Saad - AIMAF

Android

1lundi 21 janvier 13

Page 2: Formation aimaf-android-part2

Morning Program :

1. Acess and permissions

2. Layouts and screens

3. Maps and geolocation

4. Implementation of Geolocation app

Android

2lundi 21 janvier 13

Page 3: Formation aimaf-android-part2

Acess and permissions Android

A basic Android application has no permissions associated with it by default, meaning it can not do anything that would adversely impact the user experience or any data on the device. To make use of protected features of the device, you must include in your AndroidManifest.xml one or more <uses-permission> tags declaring the permissions that your application needs.

Permissions in Manifest

3lundi 21 janvier 13

Page 4: Formation aimaf-android-part2

Acess and permissions Android

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="lu.luxauto.permission.C2D_MESSAGE" android:protectionLevel="signature" />

<uses-permission android:name="lu.luxauto.permission.C2D_MESSAGE" />

<!-- App must have this permission to use the library --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.USE_CREDENTIALS" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.android.vending.BILLING" />

Sample permissins in Manifest

4lundi 21 janvier 13

Page 5: Formation aimaf-android-part2

Acess and permissions Android

Sample permissins in Manifest

5lundi 21 janvier 13

Page 6: Formation aimaf-android-part2

Acess and permissions Android

Sample permissins in Manifest

6lundi 21 janvier 13

Page 7: Formation aimaf-android-part2

Acess and permissions Android

Sample permissins

7lundi 21 janvier 13

Page 8: Formation aimaf-android-part2

Layout and screens Android

Sample permissins

8lundi 21 janvier 13

Page 9: Formation aimaf-android-part2

Layout and screens Android

View Hierarchy

9lundi 21 janvier 13

Page 10: Formation aimaf-android-part2

Layout and screens Android

Demo

10lundi 21 janvier 13

Page 11: Formation aimaf-android-part2

Map and Geolocation Android

Introduction

11lundi 21 janvier 13

Page 12: Formation aimaf-android-part2

Map and Geolocation Android

Steps of implementation

<uses-permission android:name="android.permission.INTERNET"/><uses-library android:name="com.google.android.maps"/>

Add Map Library and User Permissions

12lundi 21 janvier 13

Page 13: Formation aimaf-android-part2

Map and Geolocation Android

Steps of implementation

<uses-permission android:name="android.permission.INTERNET"/><uses-library android:name="com.google.android.maps"/>

Add Map Library and User Permissions

13lundi 21 janvier 13

Page 14: Formation aimaf-android-part2

Map and Geolocation Android

Map Layout

<?xml version="1.0" encoding="utf-8"?><com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="My Map Key"/>

Steps of implementation

14lundi 21 janvier 13

Page 15: Formation aimaf-android-part2

Map and Geolocation Android

MapActivity

public class MainActivity extends MapActivity {

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); }

Steps of implementation

15lundi 21 janvier 13

Page 16: Formation aimaf-android-part2

Map and Geolocation Android

MapActivity

public class MainActivity extends MapActivity {

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); }

Steps of implementation

16lundi 21 janvier 13

Page 17: Formation aimaf-android-part2

Map and Geolocation Android

Make sure Build target is of type

Google API

Steps of implementation

17lundi 21 janvier 13

Page 19: Formation aimaf-android-part2

Map and Geolocation Android

Get Google Map Key

19lundi 21 janvier 13

Page 20: Formation aimaf-android-part2

Map and Geolocation Android

App install

20lundi 21 janvier 13

Page 21: Formation aimaf-android-part2

Map and Geolocation Android

Marker // Add Marker List<Overlay> mapOverlays = mapView.getOverlays(); Drawable drawable = this.getResources().getDrawable(R.drawable.marker); HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this); GeoPoint point = new GeoPoint(48856628,2370228); OverlayItem overlayitem = new OverlayItem(point, "Aimaf Formation Android", "Salut les amis! nous sommes ici :)"); itemizedoverlay.addOverlay(overlayitem); mapOverlays.add(itemizedoverlay); //Add controller and animate to GeoPoint MapController mc = mapView.getController(); MyLocationOverlay myLoc = new MyLocationOverlay(this, mapView); myLoc.enableCompass(); mapView.getOverlays().add(myLoc); mc.animateTo(point);

Steps of implementation

21lundi 21 janvier 13

Page 22: Formation aimaf-android-part2

Map and Geolocation Android

ScreenShot

22lundi 21 janvier 13

Page 23: Formation aimaf-android-part2

Android

23lundi 21 janvier 13