Sunday, 3 September 2017

Android Oreo Features and APIs


Android 8.0(Android Oreo API level 26) released on August 21, 2017. Android 8.0 brings a ton of great features such as picture-in-picture, autofill, integrated Instant Apps, Google Play Protect, faster boot time, and much more.


Picture-in-Picture mode:


Picture-in-picture in Android 8.0.


Android 8.0 (API level 26) allows activities to launch in picture-in-picture (PIP) mode. PIP is a special type of multi-window mode mostly used for video playback. PIP mode is already available for Android TV; Android 8.0 makes the feature available on other Android devices.


When an activity is in PIP mode, it is in the paused state, but should continue showing content. For this reason, you should make sure your app does not pause playback in its onPause() handler. Instead, you should pause video in onStop(), and resume playback in onStart(). For more information, see Multi-Window Lifecycle.


To specify that your activity can use PIP mode, setandroid:supportsPictureInPicture to true in the manifest. (Beginning with Android 8.0, you do not need to set android:resizeableActivity to true if you are supporting PIP mode, either on Android TV or on other Android devices; you only need to setandroid:resizeableActivity if your activity supports other multi-window modes.)


Android 8.0 (API level 26) introduces a new object, PictureInPictureParams, which you pass to PIP methods to specify how an activity should behave when it is in PIP mode. This object specifies properties such as the activity's preferred aspect ratio.


The existing PIP methods described in Adding Picture-in-picture can now be used on all Android devices, not just on Android TV. In addition, Android 8.0 provides the following methods to support PIP mode:



  • Activity.enterPictureInPictureMode(PictureInPictureParams args):  Places the activity in picture-in-picture mode. The activity's aspect ratio and other configuration settings are specified by args. If any fields in args are empty, the system uses the values set the last time you called Activity.setPictureInPictureParams(). The specified activity is placed in a corner of the screen; the rest of the screen is filled with the previous activity that was on screen. The activity entering PIP mode goes into the paused state, but remains started. If the user taps the PIP activity, the system shows a menu for the user to interact with; no touch events reach the activity while it is in the PIP state.
  • Activity.setPictureInPictureParams():  Updates an activity's PIP configuration settings. If the activity is currently in PIP mode, the settings are updated; this is useful if activity's aspect ratio changes. If the activity is not in PIP mode, these configuration settings are used regardless of theenterPictureInPictureMode() method that you call.

Notifications


In Android 8.0 (API level 26), we've redesigned notifications to provide an easier and more consistent way to manage notification behavior and settings. These changes include:

A notification long-press menu in Android 8.0 (API level 26).

Users can long-press on app launcher icons to view notifications in Android 8.0.


  • Notification channels: Android 8.0 introduces notification channels that allow you to create a user-customizable channel for each type of notification you want to display. The user interface refers to notification channels as notification categories. To learn how to implement notification channels, see Managing notification channels.

  • Notification dots: Android 8.0 introduces support for displaying dots, or badges, on app launcher icons. Notification dots reflect the presence of notifications that the user has not yet dismissed or acted on. To learn how to work with notification dots, seeNotification badges.

  • Snoozing: Users can snooze notifications, which causes them to disappear for a period of time before reappearing. Notifications reappear with the same level of importance they first appeared with. Apps can remove or update a snoozed notification, but updating a snoozed notification does not cause it to reappear.

  • Notification timeouts: You can set a timeout when creating a notification using setTimeoutAfter(). You can use this method to specify a duration after which a notification should be canceled. If required, you can cancel a notification before the specified timeout duration elapses.

  • Notification settings: You can call setSettingsText() to set the text that appears when you create a link to your app's notification settings from a notification using the Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES intent. The system may provide the following extras with the intent to filter the settings your app must display to users: EXTRA_CHANNEL_ID, NOTIFICATION_TAG, and NOTIFICATION_ID.

  • Notification dismissal: Users can dismiss notifications themselves, and apps can remove them programmatically. You can determine when a notification is dismissed and why it's dismissed by implementing the onNotificationRemoved() method from the NotificationListenerServiceclass.

  • Background colors: You can set and enable a background color for a notification. You should only use this feature in notifications for ongoing tasks which are critical for a user to see at a glance. For example, you could set a background color for notifications related to driving directions, or a phone call in progress. You can also set the desired background color using setColor(). Doing so allows you to use setColorized() to enable the use of a background color for a notification.

  • Messaging style: In Android 8.0, notifications that use the MessagingStyle class display more content in their collapsed form. You should use theMessagingStyle class for notifications that are messaging-related. You can also use the addHistoricMessage() method to provide context to a conversation by adding historic messages to messaging-related notifications.

Autofill framework



Account creation, login, and credit card transactions take time and are prone to errors. Users can easily get frustrated with apps that require these types of repetitive tasks.

Android 8.0 (API level 26) makes filling out forms, such as login and credit card forms, easier with the introduction of the Autofill Framework. Existing and new apps work with Autofill Framework after the user opts in to autofill.


You can take some steps to optimize how your app works with the framework. For more information, see Autofill Framework Overview.












Downloadable fonts


Android 8.0 (API level 26) and Android Support Library 26 let you request fonts from a provider application instead of bundling fonts into the APK or letting the APK download fonts. This feature reduces your APK size, increases the app installation success rate, and allows multiple apps to share the same font.


Fonts in XML


Android 8.0 (API level 26) introduces a new feature, Fonts in XML, which lets you use fonts as resources. This means, there is no need to bundle fonts as assets. Fonts are compiled in R file and are automatically available in the system as a resource. You can then access these fonts with the help of a new resource type, font.

The Support Library 26 provides full support to this feature on devices running API versions 14 and higher.



Autosizing TextView


Android 8.0 (API level 26) lets you set the size of your text expand or contract automatically based on the size of the TextView. This means, it is much easier to optimize the text size on different screens or with dynamic content. For more information, about autosizing TextView in Android 8.0, see Autosizing TextView.


Adaptive icons






Android 8.0 (API level 26) introduces adaptive launcher icons. Adaptive icons support visual effects, and can display a variety of shapes across different device models. To learn how to create adaptive icons, see the Adaptive Icons guide.


Color management


Android developers of imaging apps can now take advantage of new devices that have a wide-gamut color capable display. To display wide gamut images, apps will need to enable a flag in their manifest (per activity) and load bitmaps with an embedded wide color profile (AdobeRGB, Pro Photo RGB, DCI-P3, etc.).


WebView APIs


Android 8.0 provides several APIs to help you manage the WebView objects that display web content in your app. These APIs, which improve your app's stability and security, include the following:
  • Version API
  • Google SafeBrowsing API
  • Termination Handle API
  • Renderer Importance API

To learn more about how to use these APIs, see Managing WebViews.

The WebView class now includes a Safe Browsing API to enhance the security of web browsing. For more information, see Google Safe Browsing API.



Pinning shortcuts and widgets



Android 8.0 (API level 26) introduces in-app pinning of shortcuts and widgets. In your app, you can create pinned shortcuts and widgets for supported launchers, subject to user permission.

For more information, see the Pinning Shortcuts and Widgets feature guide.



Maximum screen aspect ratio


Android 8.0 (API level 26) brings changes to how to configure an app's maximum aspect ratio.

First, Android 8.0 introduces the maxAspectRatio attribute, which you can use to set your app's maximum aspect ratio. In addition, in Android 8.0 and higher, an app's default maximum aspect ratio is the native aspect ratio of the device on which the app is running.




Multi-display support




Beginning with Android 8.0 (API level 26), the platform offers enhanced support for multiple displays. If an activity supports multi-window mode and is running on a device with multiple displays, users can move the activity from one display to another. When an app launches an activity, the app can specify which display the activity should run on.

Note: If an activity supports multi-window mode, Android 8.0 automatically enables multi-display support for that activity. You should test your app to make sure it works adequately in a multi-display environment.


Only one activity at a time can be in the resumed state, even if the app has multiple displays. The activity with focus is in the resumed state; all other visible activities are paused, but not stopped. For more information on the activity lifecycle when several activities are visible, see Multi-Window Lifecycle.


When a user moves an activity from one display to another, the system resizes the activity and issues runtime changes as necessary. Your activity can handle the configuration change itself, or it can allow the system to destroy the process containing your activity and recreate it with the new dimensions. For more information, see Handling Configuration Changes.


ActivityOptions provides two new methods to support multiple displays:


setLaunchDisplayId()

Specifies which display the activity should be shown on when it is launched.

getLaunchDisplayId()

Returns the activity's current launch display.

The adb shell is extended to support multiple displays. The shell start command can now be used to launch an activity, and to specify the activity's target display:


adb shell start <activity_name> --display <display_id>



Unified layout margins and padding


Android 8.0 (API level 26) makes it easier for you to specify situations where opposite sides of a View element use the same margin or padding. Specifically, you can now use the following attributes in your layout XML files:
  • layout_marginVertical, which defines layout_marginTop and layout_marginBottom at the same time.
  • layout_marginHorizontal, which defines layout_marginLeft and layout_marginRight at the same time.
  • paddingVertical, which defines paddingTop and paddingBottom at the same time.
  • paddingHorizontal, which defines paddingLeft and paddingRight at the same time.
Note: If you customize your app's logic to support different languages and cultures, including text direction, keep in mind that these attributes don't affect the values of layout_marginStart, layout_marginEnd, paddingStart, or paddingEnd. You can set these values yourself, in addition to the new vertical and horizontal layout attributes, to create layout behavior that depends on the text direction.


Pointer capture


Some apps, such as games, remote desktop, and virtualization clients, greatly benefit from getting control over the mouse pointer. Pointer capture is a new feature in Android 8.0 (API level 26) that provides such control by delivering all mouse events to a focused view in your app.

Starting in Android 8.0, a View in your app can request pointer capture and define a listener to process captured pointer events. The mouse pointer is hidden while in this mode. The view can release pointer capture when it doesn't need the mouse information anymore. The system can also release pointer capture when the view loses focus, for example, when the user opens another app.



App categories


Android 8.0 (API level 26) allows each app to declare a category that it fits into, when relevant. These categories are used to cluster together apps of similar purpose or function when presenting them to users, such as in Data Usage, Battery Usage, or Storage Usage. You can define a category for your app by setting the android:appCategory attribute in your <application> manifest tag.

Universal Android JSON Parser - JSON Reader

What is JSON? JSON stands for JavaScript Object Notation.It is an independent data exchange format and is the best alternative for XML. ...