28
Android 2.2 Froyo Robert Cooper

Android Froyo

Embed Size (px)

DESCRIPTION

30 min developer crash on new features in Froyo

Citation preview

Page 1: Android Froyo

Android 2.2 FroyoRobert Cooper

Page 2: Android Froyo

User Features

Better BlueTooth support

Better Exchange support

Improved Camera app

Better Music app

Tethering

Page 3: Android Froyo

Infrastructure

Dalvik JIT (awesome sauce)

V8 in the Browser

Support for > 256MB RAM

SDIO improvements

Page 4: Android Froyo

Stuff You Care About

Apps on External Storage

Data Backup

Device Policy Manager

Cloud to Device Messaging

New UI Goodness Car Mode Night Mode

Page 5: Android Froyo

Stuff You Care About

New Search Support

Camera Preview (Now ~20 FPS)

OpenGL ES 2.0

Improved Media Framework/OpenCore

Crash and Hang Reports on the Market

Page 6: Android Froyo

Apps on External Storage

New Compiler Framework?

This used to not work...

<uses-sdk android:minSdkVersion="4" />

With Platform compiler set in Eclipse

Page 7: Android Froyo

Apps on External Storage

<manifest xmlns:android="http://schemas.android.com/apk/res/android”package="com.totsp.crossword.shortyz” android:installLocation="preferExternal">

android:installLocation can be “preferExternal” or “auto”

Page 8: Android Froyo

Apps on External Storage

Doesn’t work when you have a …

Service

Input Method Engine

Widget or Live Folder

Live Wallpaper

Account Manager or Sync Adapter

Device Administration Receiver

Page 9: Android Froyo

Data Backup

Attaches Data to your users Android Market profile (Or other… OEM, Carrier, Whatever)

Data follows the user across devices or wipes

Page 10: Android Froyo

Data Backup

BackupAgent:

<application android:icon="@drawable/icon” android:label="@string/app_name”android:backupAgent="com.totsp.crossword.BackupAgent”android:restoreAnyVersion="true">

Page 11: Android Froyo

Backup Agent

You can implement BackupAgent yourself

Triggers onBackup() and onRestore() on the BackupAgent interface

Gives you BackupDataOutput and BackupDataInput classes

You can use these to write arbitrary binary data to a keyed data set

Page 12: Android Froyo

Data Backup

Well gee whiz Wally, that seems like a lot of work…

Page 13: Android Froyo

Data Backup

BackupAgentHelper

Allows you to compose multiple helpers to backup your data

Easy backup for SharedPrefs and Files

Databases?

Page 14: Android Froyo

Data Backup

public class BackupAgent extends BackupAgentHelper {static final String PREFS = "user_preferences”;static final String PREFS_BACKUP_KEY = "prefs”;

public void onCreate() {SharedPreferencesBackupHelper helper =

new SharedPreferencesBackupHelper(this, PREFS);

addHelper(PREFS_BACKUP_KEY, helper);}

}

Page 15: Android Froyo

Data Backup

public class MyFileBackupAgent extends BackupAgentHelper {static final String TOP_SCORES = "scores”;static final String PLAYER_STATS = "stats”;static final String FILES_BACKUP_KEY = "myfiles”; void onCreate() {

FileBackupHelper helper = new FileBackupHelper(this, TOP_SCORES, PLAYER_STATS); addHelper(FILES_BACKUP_KEY, helper);}

}

Page 16: Android Froyo

Device Policy Manager

<receiver android:name=".app.DeviceAdminSample” android:label="@string/sample_device_admin” android:description= "@string/sample_device_admin_description” android:permission= "android.permission.BIND_DEVICE_ADMIN">

<meta-data android:name="android.app.device_admin” android:resource="@xml/device_admin" />

<intent-filter>

<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />

</intent-filter>

</receiver>

Page 17: Android Froyo

Device Policy Manager

<device-admin>

<uses-policies>

<limit-password />

<watch-login />

<reset-password />

<force-lock />

<wipe-data />

</uses-policies>

</device-admin>

Page 18: Android Froyo

Device Policy Manager

DON’T DO THIS!

public void onPasswordFailed(Context context, Intent intent) {

this.getManager(context).wipeData(0);

}

Page 19: Android Froyo

Cloud to Device Messaging

Pass a K-V Pair data object to device (Intent extras)

Sent from your server, to Google

Addressed with user’s device reg id and application package name

Page 20: Android Froyo

Cloud to Device Messaging

On the device…

<permission

android:name="com.totsp.crossword.shortyz.C2D_M

ESSAGE” android:protectionLevel="signature" />

<uses-permission

android:name="com.totsp.crossword.shortyz.C2D_M

ESSAGE" />

<uses-permission

android:name="com.google.android.c2dm.permissio

n.RECEIVE" />

Page 21: Android Froyo

Cloud to Device Messaging

<receiver android:name=".PushReceiver”

android:permission="com.google.android.c2dm.permission.SEND”>

<intent-filter>

<action

android:name="com.google.android.c2dm.intent.RECEIVE" />

<category android:name="com.totsp.crossword.shortyz" />

</intent-filter>

<intent-filter>

<action

android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.totsp.crossword.shortyz" />

</intent-filter>

</receiver>

Page 22: Android Froyo

Cloud to Device Messaging

Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");

registrationIntent.putExtra(”app", PendingIntent.getBroadcast(this, 0, new Intent(), 0);

registrationIntent.putExtra("sender”,”[email protected]”);

startService(registrationIntent);

Page 23: Android Froyo

Cloud to Device Messaging

protected void onReceive(Context context, Intent intent) {

String base64data = intent.getExtras().getString(PAYLOAD);

...

Page 24: Android Froyo

Cloud to Device Messaging

Sending Messages from the Server

Step 1: Post message to https://android.apis.google.com/c2dm/send

Page 25: Android Froyo

Cloud to Device Messaging

Post Fields

registration_id : Reg id from the phone

collapse_key : A key used to prune dupes/clobbers when the phone is offline

data.[some name]: Data to push to the intent

delay_while_idle: Don’t push if the phone is idle

Authorization header for the sender

Page 26: Android Froyo

Cloud to Device Messaging

Hard Parts:

One Way – no Device to Cloud Messaging

Juggling Registration IDs in your app and from the phone Device registers, gets a reg ID posts it back to your app with your apps user

creds, etc

Where is my Google Wave “State” object for this?

Page 27: Android Froyo

UiModeManager

Lets you change the display mode or alter your display based on the current mode

UiModeManager mgr = (UiModeManager) getSystemService(UI_MODE_SERVICE);

mgr.setNightMode(UiModeManager.MODE_NIGHT_YES);

// ----

if(mgr.getCurrentModeType() == Configuration.UI_MODE_TYPE_DESK) {

Page 28: Android Froyo

Lots More

http://developer.android.com