what is new in android m
TRANSCRIPT
Android 6.0 Highlights4 Runtime Permissions
4 'Now on Tap', the Assist API and Voice Interactions
4 App Linking
4 Direct Share
4 Auto Backup for Apps
4 Doze and App Standby
4 Fingerprint Authentication and Confirm Credential
Runtime Permissions
Like the web, but different! :)
4 No blocked auto-updates!
4 User controlled!
4 Revokable
4 Simplified
Requesting permissionsif (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)) {
// Show dialog why permission is required. } else { ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); }}
Handling permission request results@Overridepublic void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the // contacts-related task you need to do.
} else { // permission denied, boo! Disable the // functionality that depends on this permission. } return; } }}
Now on Tap4 Based on the new Assist API
4 Reads meta-data from app
4 Get "smarter" over time...
4 Possible to build custom assistants!
Assist API - Opt-out with secure flag:private void disableAssistant(Activity activity) { Window window = activity.getWindow(); window.addFlag(WindowManager.LayoutParams.FLAG_SECURE);}
Assistant meta-data4 Follow accessibility guidelines!
4 Callbacks in Application and Activity classes
4 JSON-LD as defined by Schema.org
@Overridepublic void onProvideAssistContent(AssistContent assistContent) { super.onProvideAssistContent(assistContent);
String structuredJson = new JSONObject() .put("@type", "MusicRecording") .put("@id", "https://example.com/music/recording") .put("name", "Album Title") .toString();
assistContent.setStructuredData(structuredJson);}
Voice Interactions4 Started with voice command? -
Activity.isVoiceInteraction()
4 Use andorid.app.VoiceInteraction for further interactions
4 VoiceInteractor.ConfirmationRequest
4 VoiceInteractor.CommandRequest
App Linking - Automatic verification<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="www.android.com" /> <data android:scheme="https" android:host="www.android.com" /> </intent-filter>
</activity>
App Linking - assetslinks. json[{ "relation": ["delegate_permission/common.handle_all_urls"], "target": { "namespace": "android_app", "package_name": "com.example", "sha256_cert_fingerprints": ["14:6D:E9:83:C5: ... :3F:CF:44:E5"] }}]
Direct Share - Manifest<service android:name=".MyChooserTargetService" android:label="@string/service_name" android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE"> <intent-filter> <action android:name="android.service.chooser.ChooserTargetService" /> </intent-filter></service>
<activity android:name=".MyShareActivity" android:label="@string/share_activity_label"> <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>
Implementing ChooserTargetServicepublic class MyChooserTargetService extends ChooserTargetService {
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) { Icon chooserIcon = Icon.createWithBitmap(getBitmapForTarget()); ComponentName targetActivity = new ComponentName(this, TargetActivity.class); Bundle extras = new Bundle(); // Populate as needed ChooserTarget target = new ChooserTarget("Title", chooserIcon, targetActivity, extras);
// TODO Create a list of ChooserTargets...
return chooserTargets; }}
Doze restrictions4 Network access is suspended.
4 The system ignores wake locks.
4 Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.
4 If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
4 Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire.
4 The system does not perform Wi-Fi scans.
4 The system does not allow sync adapters to run.
4 The system does not allow JobScheduler to run.
Doze and AlarmManagerAlarmManager.setAndAllowWhileIdle() and AlarmManager.setExactAndAllowWhileIdle()
4 Adds your app to a temporary whitelist for 10 seconds!
4 Can't run more than every 15 minutes!
4 Can be rescheduled by the system!
How to avoid it!4 Let the user whitelist your app from AppStandbyPowerManager alarmManager = context.getSystemService(PowerManager.class);if(!alarmManager.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID)) { Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); context.startActivity(intent);}
Auto Backup for Apps4 Limited to 25 MB app data
4 Use android:fullBackupContent="@xml/mybackupscheme" in the application tag for configuration
<full-backup-content> <include domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string" /> <exclude domain=["file" | "database" | "sharedpref" | "external" | "root"] path="string" /></full-backup-content>
Fingerprint Authentication4 Use in conjunction with Android
Keystore system<uses-permission android:name="android.permission.USE_FINGERPRINT" />
Fingeprint AuthenticationFingerprintManager mgr = context.getSystemService(FingerprintManager.class);mgr.authenticate(...);
Confirm Credential4 Invalidates a key from the Keystore after a certain
periodkeyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) .setBlockModes(KeyProperties.BLOCK_MODE_CBC) .setUserAuthenticationRequired(true) // Invalidate this key after 2 minutes inactivity... .setUserAuthenticationValidityDurationSeconds(120) .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7) .build());keyGenerator.generateKey();
android { compileSdkVersion 23 buildToolsVersion "23.0.1"
defaultConfig { applicationId "com.awesomeapp" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" }}
Apache HTTP Client Removal4 org.apache.http is removed from the APIs
4 Still available at runtime!
4 Can be re-enabled in build.gradle:
android { useLibrary 'org.apache.http.legacy'}
4 Highly discouraged!