i/o rewind 215: what's new in android
TRANSCRIPT
#IORewind
What’s new in Android M
nuuneoi
#IORewind
MStands for ...
mmmm
#IORewind
MStands for ...
Preview
#IORewind
Building M Preview Apps
Android M is now available on SDK Manager
#IORewind
Building M Preview Apps
#IORewind
Previewssssss
#IORewind
OK. Let’s start.
#IORewind
Apps PermissionFASTER INSTALLS • SMOOTHER UPGRADES • MORE USER
CONTROL
#IORewind
Install-time permissions
#IORewind
Runtime permissions in M
#IORewind
User controls in M
#IORewind
Everything you’ve ever asked for
But now your app has to deal with it
#IORewind
Apps targeting M can: can ask for any permission at any timeLegacy apps will: get all permissions at install time, as beforeUsers can: deny any permissions upon request deny any permissions at any later time – even legacy appsTest!
#IORewind
Voice Interactions
#IORewind
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>
#IORewind
Voice Interactions
public class MyVoiceActivity extends AppCompatActivity {
@Override protected void onResume() { super.onResume(); if (isVoiceInteraction()) { // do stuff } else { finish(); } }
#IORewind
Voice Interactions
public class MyVoiceActivity extends AppCompatActivity {
@Override protected void onResume() { super.onResume(); if (isVoiceInteraction()) { String prompt = "..."; getVoiceInteractor().submitRequest( new Confirm(prompt)); } else { finish(); } }
#IORewind
Voice Interactions
public class Confirm extends VoiceInteractor.ConfirmationRequest {
public Confirm(String prompt) { super(prompt, null); }
@Override public void onConfirmationResult( boolean confirmed, Bundle result) { if (confirmed) { // do stuff } }
}
public class MyVoiceActivity extends AppCompatActivity {
@Override protected void onResume() { super.onResume(); if (isVoiceInteraction()) { String prompt = "..."; getVoiceInteractor().submitRequest( new Confirm(prompt)); } else { finish(); } }
#IORewind
FingerprintQUICK USER VERIFICATION
#IORewind
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
#IORewind
Android BackupRESTORATION SOFTWARE
#IORewind
Android Backup
All data now backed up by default targetSdk M
Optional scheme file in xml/ resource dir includes/excludes
#IORewind
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>
#IORewind
Google Play Services
7.5 AND COUNTING
#IORewind
GCM Network Manager
Like JobScheduler … but across releases
OneOffTaskPeriodicTask
Limit network requests to wifi, or charging, or …
#IORewind
Also…
Maps on Android WearApp InvitesCast Remote DisplaySmart Lock for Passwords…
#IORewind
PowerEVEN BETTER BATTERY LIFE
#IORewind
Power improvements
Better screen-off battery lifeDoze Untouched devices become “inactive” Wait longer to wake up for background tasks Resume normal operation when moved, used, or plugged inApp standby Unused apps lose network access Resume when launched/used or when plugged in
#IORewind
Assistant Support
CONTEXTUAL INFORMATION, WHEN THE USER NEEDS IT
#IORewind
Assistant Support
New APIs to provide the assistant with relevant data
See SDK docs: Activity.onProvideAssistData(Bundle) Application.OnProvideAssistDataListener
#IORewind
Data BindingBOUNDS AND DETERMINED
#IORewind
Data Binding
Connecting data and UI elements Automates listener creation, message sending, setters, …Pre-processed at build time
#IORewind
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>
#IORewind
UI FeaturesALL ABOUT YOU AND I
#IORewind
Android Design Support Library
Snackbar
#IORewind
Android Design Support Library
SnackbarFAB
#IORewind
Android Design Support Library
SnackbarFABCoordinatorLayout
#IORewind
Android Design Support Library
SnackbarFABCoordinatorLayoutTabLayout
#IORewind
Android Design Support Library
SnackbarFABCoordinatorLayoutTabLayoutTextInputLayout
#IORewind
Android Design Support Library
SnackbarFABCoordinatorLayoutTabLayoutTextInputLayoutNavigationView
#IORewind
Other UI Changes
RecyclerView ItemTouchHelper Swipe-to-dismiss
Drag & drop
WebView PostMessage
WebViewClient
WebSettings.setOffscreenPreRaster()
#IORewind
NotificationsHEY! YOU THERE! LOOK UP HERE!
#IORewind
android.graphics.drawable.Icon
Holds either: a drawable resource id
a Bitmap
a byte[] holding a PNG or JPEG
#IORewind
Icons in Notifications
Icon ic = Icon.createWithResource(context, R.drawable.ic_notification);Notification no = Notification.Builder(context) .setSmallIcon(ic) ... .build();
#IORewind
Icons in Notifications
Icon ic = Icon.createWithBitmap(iconBitmap);
Notification no = Notification.Builder(context) .setSmallIcon(ic) ... .build();
#IORewind
Text StuffsTEXT IS ALL AROUND
#IORewind
Text Selection
Easier SelectionFloating palette with action items Default for TextView
Other views set ActionMode.TYPE_FLOATING
#IORewind
Text Processing
<intent-filter> <action android:name="android.intent.action.PROCESS_TEXT"/></intent-filter>
#IORewind
Higher Quality Text Formatting
TextView.setBreakStrategy(int);
TextView.setHyphenationFrequency(int);
TextView.setIndents(int[] left, int[] right);
#IORewind
App LinksRELATIONSHIP BETWEEN APP AND WEB DOMAINS
#IORewind
App Links
Understand the relationshipbetween an app and web domainsowned by the same developer
d.android.com/preview/features/app-linking.html
#IORewind
[{ "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
#IORewind
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
#IORewind
<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
#IORewind
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
#IORewind
Direct ShareSHARING IS EVEN MORE AWESOME
#IORewind
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 }}
#IORewind
Stylus supportNOW THE PRESSURE IS REALLY ON
#IORewind
Styluses: supported sinceICE_CREAM_SANDWICHMotionEvent APIs: TOOL_TYPE_STYLUS BUTTON_SECONDARY BUTTON_TERTIARY getPressure(), getSize(), getOrientation(), etc.
Until now, this only worked for wired/builtin digitizers
#IORewind
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
#IORewind
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
#IORewind
Graphics & Media
IT’S ALL ABOUT THE PIXELS
#IORewind
RenderScript Compute
BLAS intrinsics (Really big matrices)
Allocation-less launches Size of kernel separate from data
ScriptGroup More dependency types
Better compiler optimizations
#IORewind
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) {}
}
#IORewind
Alpha Optimization
Auto hardware layer for translucent Views
Call setLayerType() yourself still a Good idea
#IORewind
MIDI
Your could already do this… … but it was a lot of work
Introducing … android.media.midi MidiDeviceManager MidiInputPort
MidiOutputPort
MidiDeviceService
#IORewind
High Resolution Audio
Audio samples: single-precision float
Sample rate: 96 kHz
USB digital audio: multichannel
#IORewind
ToolsMAKE IT HAPPENS
#IORewind
Android Studio
Integrated testing supportData bindingVector drawablesNew annotationsAndroid NDK
#IORewind
Systrace
#IORewind
Systrace
ListView item recycling involved inflating views. EnsureYour Adapter#getView() recycles the incoming View,Instead of constructing a new one.
#IORewind
ART
Compiler optimizations register allocator global value number loop-invariant code motion dead code elimination bounds check elimination constant folding inlining
#IORewind
ART
Runtime stats Debug.getRuntimeStat(String)
“art.gc.gc-count”
“art.gc.gc-time”
…
#IORewind
MiscREALLY IMPORTANT STUFF WE COULDN’T EASILY CATEGORIZE
#IORewind
External Storage
“Adopt” permanent storageAvoid hard-coded pathsNo new APIs!For Preview testing: $ adb root && sleep 2
$ adb shell setprop persist.fw.force_adoptable 1
$ adb reboot
#IORewind
Developing for Android
Guide for better mobile apps
medium.com/google-developers
#IORewind
So what are you waiting for?
Preview: d.android.com/preview
SDK + Android Studio: d.android.com/sdk
System image: d.android.com/sdk
Report bugs: code.google.com/android-developer-preview
DevBytes: youtube.com/GoogleDevelopers
#IORewind
Thank youQ&A