Android 7.0(Nougat)
Nougat is the seventh major version of Android operating system.It is named as Android N during developement.First beta version of Nougat was released on March 9, 2016.It was officially released on August 22, 2016.API level 24 is introduced for Nougat.
New Features :
Multi-window Support
- Two apps can be open on the screen at once.
- Users can run two apps side by side or one above the other in split mode.Apps also can be resize by dragging the divider between them.
Implementation : - An Activity can be set as not resizable by setting a properties in manifest-
android:resizableActivity = ”false”;
All apps targeting Android N or above are resizable by default. - In split-screen mode an Activity is called adjacent to launching Activity by setting following flag in its Intent-
Intent.FLAG_ACTIVITY_LAUNCH_TO_ADJACENT - To enable all callbacks on configuration changes during multi-window use for activity ,you need to set following configuration with respected Activity in manifest-
android:configChanges = screenSize | smallestScreenSize | screenLayout | orientation
Notification Enhancements
- Direct reply of notifications from notification bar without opening any app.
- Concept of bundled notification is introduced in Nougat.User can see what’s new at a glance from app.
- User can simply open and view notifications from notification bar without having open app.
Implementation :
Nougat supports a special action for direct reply and allow the users to input text right into the notification interface, and our application to receive it, without being brought to foreground.Refer following code snippet -
//Defining Pending Intent for reply action
//RemoteInput
- A Remote Input required to collect input from a user and to passed it along with an intent inside a PendingIntent.
- Following example add a Remote Input to Notification Action,sets the result key as quick_reply and set label as Reply.User are prompted to input a response when they triggered the action.
- The results are sent along with the intent and can be retrieved with the result key.
//NotificationCompatBuilder
//BroadcastReceiver
- A Broadcast Receiver is required because We need to handle whatever user inputs to DirectReply action.
- Result is retrieved with result key from the bundle returned with intent.
- As shown in above code ,we try to get RemoteInput from intent that is passed to onReceive() method.If its not there,it means that current Android platform doesn’t support this feature and we can gracefully return from method.If it’s there,we can retrieve message and act on it.
Profile -Guided JIT/AOT Compilation
- Nougat introduces a hybrid runtime using compilation+interpretation+JIT to achieve best compromise between installation time, memory, power consumption and performance.
- The installation time of apps is reduced.
- System updates are installed faster because they do not require an optimization step.
- Hybrid runtime strategy of Nougat ensures performance improvements and low power consumption.
Doze on go
- Doze feature introduced in Marshmallow(Android 6.0) .It saves battery by deferring apps CPU and network activities when the device is idle.
- Doze periodically blocks wakelocks and shut off network access if your phone goes unused for a while.It will then priodically allow apps check in during Maintenance Windows.These windows occur less frequently the longer you do not use your phone.
- In Nougat, Doze is extended to one more step and it saves battery while on the go.
- Any time the screen is off for a period of time and the device is unplugged, Doze applies a subset of the familiar CPU and network restrictions to apps.
Background Optimization
- Since Lollipop (Android 5.0) JobScheduler has been the preferred way of performing background work. Apps can schedule jobs while letting the system optimize based on memory, power, and connectivity conditions. JobScheduler offers control and simplicity.
- To minimize RAM use by system and apps across the range of Android devices in the ecosystem,Project Svelte is introduced. In Android 7.0, Project Svelte is focused on optimizing the way apps run in the background.
Surfaceview
- Nougat introduces Surfaceview for better battery performances than Textureview in certain conditions : When rendering video or 3D content, apps with scrolling and animated video position use less power with SurfaceView than with TextureView.
//SurfaceView Implementation
- onDraw() method was called directly from holder if we had extended View class.In View class there were no callbacks when view is created.But in case of SurfaceView, we have a surfaceCreated() method and we can call onDraw() method explicitly by passing canvas as a parameter.
Data Saver
- Nougat introduces Data Saver mode which helps to reduce cellular data use by apps.
- When Data Saver mode is enabled by user, the system blocks background data usage and signals apps to use less data in foreground.User can specify apps to allow background data usage when Data Saver mode is turned on.
Vulkan API
- Vulkan is an open standard 3D graphics and rendering API developed by Khronos group .
- Vulkan is available for devices with vulkan-capable hardware such as Nexus 5X, Nexus 6P and Nexus player.
Display Size and Quick Settings Tile API
- User can change size of icons for better experience.
- User can change the position of quick setting tiles by swipe them left or right. Nougat also adds an API to let users define their own quick settings tiles.
Number Blocking and Call Screening
- Nougat introduces a new feature that allows users to block a number directly from new phone application on your device.
- Call screening is introduced with default dialer app.User can do three things while incoming call -reject the incoming call, prevent the number from showing up on call log and stop the dialer from showing a notification.
Multi Language Support and New Emojis
- Android has already a feature to choose main language but Nougat allows user to easily select and use multiple languages on a single device .For this, multi locale language setting is provided and there are 25 variants of commonly used languages .Partial support of 100 new languages is also provided.
- Android facilitates almost 1500 emojis. 72 new skin tone emojis and support for variants selector is introduced in Nougat.
Webview
- Starting with Chrome version 51 on Android 7.0 and above, the Chrome APK on your device is used to provide and render Android System WebViews. This approach improves memory usage on the device itself and also reduces the bandwidth required to keep WebView up to date (as the standalone WebView APK will no longer be updated as long as Chrome remains enabled).
- Webview provider can change by enabling developer options and selecting Webview implementation.
- Nougat enables javascript to run before page load.
Direct boot
- Nougat introduces a new feature as Direct boot .This improves device startup time and makes app to run securely even before entering your password.
- To support Direct boot mode Nougat enables system to provide two storage location for data :
Credential encrypted storage — This is default storage location
and available after device is unlocked.
Device encrypted storage — This is storage location available at both
during Direct boot mode and after the user has unlocked the device.
- App’s components must be registered with system to run app in direct boot mode or access Device encrypted storage.
- App’s components need to mark encryption aware to run in direct boot mode.
- To mark components encryption aware ,following property need to be set in manifest.
android:directBootAware =”true”
Key Attestation
- This is a new security tool introduced in Nougat which allows developer to make sure the keys are being use in their apps are valid and stored in device’s hardware — backed keystore and not in software.
- Only very few devices running Android 7.0 support hardware-level key attestation,all other devices use software-level key attestation instead but developer can check boot state to ensure that the system software hasn’t tampered with.
Accessibility Enhancement
- Nougat allows users to zoom in or zoom out on their desired screen of phone.Size of text and icon also can be adjust.
- Screen Zoom actually changes the display density to magnify or shrink everything on the screen.
- Status bar and on screen navigation button can also change by using Zoom Screen tool.
Scoped Directory Access
- Nougat introduces new APIs to access desired external storage directories instead of accessing all the directories of external storage using READ_EXTERNAL_STORAGE.As an example if you need to access only photos, you can refer following code:
- Many other constants are provided in Nougat to access other directories of external storage.
Virtual Files
- Nougat introduces the concept of virtual files.In earlier versions of android there was no way to reperesent the files that does not have direct bytecode representation ,every file was required to provide input stream.This problem was with apps that allows user to select files from their cloud accounts storage like Google Drive.
- To open virtual files your client’s app need to include some logic to handle them.To get URI for virtual documents, you need to create an intent to open File Picker UI.
//Creating an Intent
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
- After selection,onActivityResult() method is called by system and app receives an URI.You need to determine wheather this is a virtual file using a method similar to following code :
- Once you have verified that file is virtual ,you can get input stream from virtual file by using following code snippet :
- After knowing the input stream type you can coerce the file into an alternative MIME type.