Обзор Android M

103
What’s new in Android M

Transcript of Обзор Android M

What’s new in Android M

Building M Preview Apps

Android M is now available on SDK Manager

Building M Preview Apps

Previewssssss

OK. Let’s start.

Apps PermissionFASTER INSTALLS • SMOOTHER UPGRADES • MORE USER CONTROL

Install-time permissions

Runtime permissions in M

User controls in M

Everything you’ve ever asked for

But now your app has to deal with it

Apps targeting M can:

can ask for any permission at any time

Legacy apps will:

get all permissions at install time, as before

Users can:

deny any permissions upon request

deny any permissions at any later time – even legacy apps

Voice Interactions

Voice Interactions

VoiceInteractor – confirm and prompt for response

<activity android:name="org.example.MyVoiceActivity">

<intent-filter>

<action android:name="org.example.MY_ACTION_INTENT" />

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

<category android:name="android.intent.category.VOICE" />

</intent-filter>

</activity>

Voice Interactions

public class MyVoiceActivityextends AppCompatActivity {

@Overrideprotected void onResume() {

super.onResume();if (isVoiceInteraction()) {

// do stuff} else {

finish();}

}

Voice Interactions

public class MyVoiceActivityextends AppCompatActivity {

@Overrideprotected void onResume() {

super.onResume();if (isVoiceInteraction()) {

String prompt = "...";getVoiceInteractor().submitRequest(

new Confirm(prompt));} else {

finish();}

}

Voice Interactions

public class Confirm extendsVoiceInteractor.ConfirmationRequest {

public Confirm(String prompt) {super(prompt, null);

}

@Overridepublic void onConfirmationResult(

boolean confirmed, Bundle result) {if (confirmed) {

// do stuff}

}

}

public class MyVoiceActivityextends AppCompatActivity {

@Overrideprotected void onResume() {

super.onResume();if (isVoiceInteraction()) {

String prompt = “Are you sure?";getVoiceInteractor().submitRequest(

new Confirm(prompt));} else {

finish();}

}

FingerprintQUICK USER VERIFICATION

Two APIs for fingerprints

FingerprintManager.authenticate()

Verify that authorized user is present

Your app controls all UI

KeyguardManager.createConfirmDeviceCredentialIntent()

Present lock screen to user

startActivityForResult(), check for RESULT_OK

Sample code

github.com/googlesamples/android-FingerprintDialog

github.com/googlesamples/android-ConfirmCredential

Android BackupRESTORATION SOFTWARE

Android Backup

All data now backed up by default

targetSdk M

Optional scheme file in xml/ resource dir

includes/excludes

Android Backup

AndroidManifest.xml

<application android:fullBackupContent="@xml/mybackupscheme">...

</application>

res/xml/mybackupscheme.xml

<full-backup-content><exclude domain="database" path="device_info.db"/>

</full-backup-content>

or

<full-backup-content><include domain="file" path="mydata/allthatmatters.txt"/>

</full-backup-content>

Google Play Services7.5 AND COUNTING

GCM Network Manager

Like JobScheduler

… but across releases

OneOffTask

PeriodicTask

Limit network requests to wifi, or charging, or …

Also…

Maps on Android Wear

App Invites

Cast Remote Display

Smart Lock for Passwords

PowerEVEN BETTER BATTERY LIFE

Power improvements

Better screen-off battery life

Doze

Untouched devices become “inactive”

Wait longer to wake up for background tasks

Resume normal operation when moved, used, or plugged in

App standby

Unused apps lose network access

Resume when launched/used or when plugged in

Assistant SupportCONTEXTUAL INFORMATION, WHEN THE USER NEEDS IT

Assistant Support

New APIs to provide the assistant with relevant data

See SDK docs:

Activity.onProvideAssistData(Bundle)

Application.OnProvideAssistDataListener

Data BindingBOUNDS AND DETERMINED

Data Binding

Connecting data and UI elements

Automates listener creation, message sending, setters, …

Pre-processed at build time

Data Binding<layout>

<data><variable name="item" type="com.android.example.store.Item"/>

</data><FrameLayout ...>

<ImageView ... android:src="@{item.image}" /><TextView ... android:text="@{@string/price(item.dollars, item.cents)}" />

</FrameLayout></layout>

UI FeaturesALL ABOUT YOU AND I

Android Design Support Library

Snackbar

Android Design Support Library

Snackbar

FAB

Android Design Support Library

Snackbar

FAB

CoordinatorLayout

Android Design Support Library

Snackbar

FAB

CoordinatorLayout

TabLayout

Android Design Support Library

Snackbar

FAB

CoordinatorLayout

TabLayout

TextInputLayout

Android Design Support Library

Snackbar

FAB

CoordinatorLayout

TabLayout

TextInputLayout

NavigationView

Other UI Changes

RecyclerView ItemTouchHelper

Swipe-to-dismiss

Drag & drop

NotificationsHEY! YOU THERE! LOOK UP HERE!

android.graphics.drawable.Icon

Holds either:

a drawable resource id

a Bitmap

a byte[] holding a PNG or JPEG

Icons in Notifications

Icon ic = Icon.createWithResource(context,R.drawable.ic_notification);

Notification no = Notification.Builder(context).setSmallIcon(ic)....build();

Icons in Notifications

Icon ic = Icon.createWithBitmap(iconBitmap);

Notification no = Notification.Builder(context).setSmallIcon(ic)....build();

Text StuffsTEXT IS ALL AROUND

Text Selection

Easier Selection

Floating palette with action items

Default for TextView

Other views

set ActionMode.TYPE_FLOATING

App LinksRELATIONSHIP BETWEEN APP AND WEB DOMAINS

App Links

Understand the relationship

between an app and web domains

owned by the same developer

d.android.com/preview/features/app-linking.html

[{"relation": ["delegate_permission/common.handle_all_urls"],"target": {"namespace": "android_app","package_name": “com.example.myapp","sha256_cert_fingerprints": ["6C:EC:C5:0E:34:AE....EB:0C:9B"]

}

}]

http://example.com/.well-known/statements.json

https: for M final

keytool -list -v -keystore release.keystore

Establishing app links

At install time

Package Manager fetches statements.json

Matches hash to APK’s signing certificate

These links will now launch your app

On failure, a link is not created

Usual intent chooser will be shown

Users can review & modify app links

Settings -> Apps -> (Your App) -> Open by default

<activity ...><intent-filter android:autoVerify="true">

<action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><data android:scheme="http" android:host=“example.com" /><data android:scheme="http" android:host="www.example.com" />

</intent-filter>

</activity>

AndroidManifest.xml

This is where we will look for /.well-known/statements.json

Establishing app links

At install time

Package Manager fetches statements.json

Matches hash to APK’s signing certificate

These links will now launch your app

On failure, a link is not created

Usual intent chooser will be shown

Users can review & modify app links

Settings -> Apps -> (Your App) -> Open by default

Direct ShareSHARING IS EVEN MORE AWESOME

Direct Share<activity ...>

<intent-filter><action android:name="android.intent.action.SEND" />

</intent-filter><meta-data android:name="android.service.chooser.chooser_target_service"

android:value=".MyChooserTargetService" />

</activity>

<service android:name=".MyChooserTargetService"android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"><intent-filter>

<action android:name="android.service.chooser.ChooserTargetService" /></intent-filter>

</service>

public class MyChooserTargetService extends ChooserTargetService {

@Override

public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName,

IntentFilter matchedFilter) {

// do stuff

}

}

Stylus supportNOW THE PRESSURE IS REALLY ON

Styluses: supported sinceICE_CREAM_SANDWICH

MotionEvent APIs:

TOOL_TYPE_STYLUS

BUTTON_SECONDARY

BUTTON_TERTIARY

getPressure(), getSize(), getOrientation(), etc.

Until now, this only worked for wired/builtin digitizers

Bluetooth stylus support

Want to make a Bluetooth stylus?

Report pressure and buttons using Bluetooth HID

Android M will fuse this with touch events

Result touch stream will be TOOL_TYPE_STYLUS

(or TOOL_TYPE_ERASER)

Bluetooth stylus support for every app and every M device

New stylus API in M

Button support

ACTION_BUTTON_PRESS, ACTION_BUTTON_RELEASE,

BUTTON_STYLUS_PRIMARY, BUTTON_STYLUS_SECONDARY

Gesture support

ScaleGestureDetector.setStylusScaleEnabled(bool)

Quick scale with button-click+drag

OnGestureListener.onStylusButtonPress

Use this for selection & drag-and-drop

Graphics & MediaIT’S ALL ABOUT THE PIXELS

RenderScript Compute

BLAS intrinsics

(Really big matrices)

Allocation-less launches

Size of kernel separate from data

ScriptGroup

More dependency types

Better compiler optimizations

Camera

New Torch mode

Independent of camera device

CameraManager.setTorchMode(String cameraId, boolean enabled);

public abstract class CameraManager.TorchCallback {

public void onTorchModeUnavailable(String cameraId) {}

public void onTorchModeChanged(String cameraId, boolean enabled) {}

}

MIDI

Your could already do this…

… but it was a lot of work

Introducing … android.media.midi

MidiDeviceManager

MidiInputPort

MidiOutputPort

MidiDeviceService

High Resolution Audio

Audio samples: single-precision float

Sample rate: 96 kHz

USB digital audio: multichannel

ToolsMAKE IT HAPPENS

Android Studio

Integrated testing support

Data binding

Vector drawables

New annotations

Android NDK

Systrace

Systrace

ListView item recycling involved inflating views. EnsureYour Adapter#getView() recycles the incoming View,Instead of constructing a new one.

ART

Compiler optimizations

register allocator

global value number

loop-invariant code motion

dead code elimination

bounds check elimination

constant folding

inlining

ART

Runtime stats

Debug.getRuntimeStat(String)

“art.gc.gc-count”

“art.gc.gc-time”

Thank youQ&A