leaderboard 1

Tuesday, 29 September 2015

Android 5.0 APIs

Android 5.0 APIs



API Level: 21
Android 5.0 (LOLLIPOP) offers new features for users and app developers. This document provides an introduction to the most notable new APIs.
If you have a published app, make sure to check out the Android 5.0 Behavior Changes that you should account for in your app. These behavior changes may affect your app on Android 5.0 devices, even if you are not using new APIs or targeting new functionality.
For a high-level look at the new platform features, instead see the Android Lollipop highlights.

Start developing

To start building apps for Android 5.0, you must first get the Android SDK. Then use the SDK Manager to download the Android 5.0 SDK Platform and System Images.

Update your target API level

To better optimize your app for devices running Android 5.0, set yourtargetSdkVersion to "21", install your app on an Android 5.0 system image, test it, then publish the updated app with this change.
You can use Android 5.0 APIs while also supporting older versions by adding conditions to your code that check for the system API level before executing APIs not supported by your minSdkVersion. To learn more about maintaining backward compatibility, read Supporting Different Platform Versions.
For more information about how API levels work, read What is API Level?

Important behavior changes

If you have previously published an app for Android, be aware that your app might be affected by changes in Android 5.0.
Please see Android 5.0 Changes for complete information.

User Interface


Material design support

Android 5.0 adds support for Android's new material design style. You can create apps with material design that are visually dynamic and have UI element transitions that feel natural to users. This support includes:
  • The material theme
  • View shadows
  • The RecyclerView widget
  • Drawable animation and styling effects
  • Material design animation and activity transition effects
  • Animators for view properties based on the state of the view
  • Customizable UI widgets and app bars with color palettes that you control
  • Animated and non-animated drawables based on XML vector graphics
To learn more about adding material design functionality to your app, see Material Design.

Concurrent documents and activities in the recents screen

In previous releases, the recents screen could only display only one task for each app that the user interacted with most recently. Now your app can open more tasks as needed for additional concurrent activities for documents. This feature facilitates multitasking by letting users quickly switch between individual activities and documents from the recents screen, with a consistent switching experience across all apps. Examples of such concurrent tasks might include open tabs in a web browser app, documents in a productivity app, concurrent matches in a game, or chats in a messaging app. Your app can manage its tasks through the ActivityManager.AppTask class.
To insert a logical break so that the system treats your activity as a new task, use FLAG_ACTIVITY_NEW_DOCUMENT when launching the activity with startActivity(). You can also get this behavior by setting the <activity> element'sdocumentLaunchMode attribute to "intoExisting" or "always" in your manifest.
To avoid cluttering the recents screen, you can set the maximum number of tasks from your app that can appear in that screen. To do this, set the <application> attribute android:maxRecents. The current maximum that can be specified is 50 tasks per user (25 for low RAM devices).
Tasks in the recents screen can be set to persist across reboots. To control the persistence behavior, use theandroid:persistableMode attribute. You can also change the visual properties of an activity in the recents screen, such as the activity’s color, label, and icon, by calling the setTaskDescription() method.

WebView updates

Android 5.0 updates the WebView implementation to Chromium M37, bringing security and stability enhancements, as well as bug fixes. The default user-agent string for a WebView running on Android 5.0 has been updated to incorporate 37.0.0.0 as the version number.
This release introduces the PermissionRequest class, which allows your app to grant the WebView permission to access protected resources like the camera and microphone, through web APIs such as getUserMedia(). Your app must have the appropriate Android permissions for these resources in order to grant the permissions to the WebView.
With the new onShowFileChooser() method, you can now use an input form field in the WebView, and launch a file chooser to select images and files from the Android device.
Additionally, this release brings support for the WebAudioWebGL, and WebRTC open standards. To learn more about the new features included in this release, see WebView for Android.

Screen capturing and sharing

Android 5.0 lets you add screen capturing and screen sharing capabilities to your app with the newandroid.media.projection APIs. This functionality is useful, for example, if you want to enable screen sharing in a video conferencing app.
The new createVirtualDisplay() method allows your app to capture the contents of the main screen (the default display) into a Surface object, which your app can then send across the network. The API only allows capturing non-secure screen content, and not system audio. To begin screen capturing, your app must first request the user’s permission by launching a screen capture dialog using an Intent obtained through the createScreenCaptureIntent() method.
For an example of how to use the new APIs, see the MediaProjectionDemo class in the sample project.

Notifications


Lock screen notifications

Lock screens in Android 5.0 have the ability to present notifications. Users can choose via Settings whether to allow sensitive notification content to be shown over a secure lock screen.
Your app can control the level of detail visible when its notifications are displayed over the secure lock screen. To control the visibility level, call setVisibility() and specify one of these values:
  • VISIBILITY_PRIVATE: Shows basic information, such as the notification’s icon, but hides the notification’s full content.
  • VISIBILITY_PUBLIC: Shows the notification’s full content.
  • VISIBILITY_SECRET: Shows nothing, excluding even the notification’s icon.
When the visibility level is VISIBILITY_PRIVATE, you can also provide a redacted version of the notification content that hides personal details. For example, an SMS app might display a notification that shows "You have 3 new text messages" but hides the message content and senders. To provide this alternative notification, first create the replacement notification using Notification.Builder. When you create the private notification object, attach the replacement notification to it through the setPublicVersion() method.

Notifications metadata

Android 5.0 uses metadata associated with your app notifications to sort the notifications more intelligently. To set the metadata, call the following methods in Notification.Builder when you construct the notification:
  • setCategory(): Tells the system how to handle your app notifications when the device is in priority mode (for example, if a notification represents an incoming call, instant message, or alarm).
  • setPriority(): Marks the notification as more or less important than normal notifications. Notifications with the priority field set to PRIORITY_MAX or PRIORITY_HIGH appear in a small floating window if the notification also has sound or vibration.
  • addPerson(): Enables you to add one or more people who are relevant to a notification. Your app can use this to signal to the system that it should group together notifications from the specified people, or rank notifications from these people as being more important.

Graphics


Support for OpenGL ES 3.1

Android 5.0 adds Java interfaces and native support for OpenGL ES 3.1. Key new functionality provided in OpenGL ES 3.1 includes:
  • Compute shaders
  • Separate shader objects
  • Indirect draw commands
  • Multisample and stencil textures
  • Shading language improvements
  • Extensions for advanced blend modes and debugging
  • Backward compatibility with OpenGL ES 2.0 and 3.0
The Java interface for OpenGL ES 3.1 on Android is provided with GLES31. When using OpenGL ES 3.1, be sure that you declare it in your manifest file with the <uses-feature> tag and the android:glEsVersion attribute. For example:
<manifest>
    <uses-feature android:glEsVersion="0x00030001" />
    ...</manifest>
For more information about using OpenGL ES, including how to check the device’s supported OpenGL ES version at runtime, see the OpenGL ES API guide.

Android Extension Pack

In addition to OpenGL ES 3.1, this release provides an extension pack with Java interfaces and native support for advanced graphics functionality. These extensions are treated as a single package by Android. (If theANDROID_extension_pack_es31a extension is present, your app can assume all extensions in the package are present and enable the shading language features with a single #extension statement.)
The extension pack supports:
  • Guaranteed fragment shader support for shader storage buffers, images, and atomics (Fragment shader support is optional in OpenGL ES 3.1.)
  • Tessellation and geometry shaders
  • ASTC (LDR) texture compression format
  • Per-sample interpolation and shading
  • Different blend modes for each color attachment in a frame buffer
The Java interface for the extension pack is provided with GLES31Ext. In your app manifest, you can declare that your app must be installed only on devices that support the extension pack. For example:
<manifest>
    <uses-feature android:name=“android.hardware.opengles.aep”
        android:required="true" />
    ...</manifest>

Media


Camera API for advanced camera capabilities

Android 5.0 introduces the new android.hardware.camera2 API to facilitate fine-grain photo capture and image processing. You can now programmatically access the camera devices available to the system with getCameraIdList()and connect to a specific device with openCamera(). To start capturing images, create a CameraCaptureSession and specify the Surface objects to send captured images. The CameraCaptureSession can be configured to take single shots or multiple images in a burst.
To be notified when new images are captured, implement the CameraCaptureSession.CaptureCallback listener and set it in your capture request. Now when the system completes the image capture request, yourCameraCaptureSession.CaptureCallback listener receives a call to onCaptureCompleted(), providing you with the image capture metadata in a CaptureResult.
The CameraCharacteristics class lets your app detect what camera features are available on a device. The object'sINFO_SUPPORTED_HARDWARE_LEVEL property represents the camera's level of functionality.
To see how to use the updated Camera API, refer to the Camera2Basic and Camera2Video implementation samples in this release.

Audio playback

This release includes the following changes to AudioTrack:
  • Your app can now supply audio data in floating-point format (ENCODING_PCM_FLOAT). This permits greater dynamic range, more consistent precision, and greater headroom. Floating-point arithmetic is especially useful during intermediate calculations. Playback endpoints use integer format for audio data, and with lower bit depth. (In Android 5.0, portions of the internal pipeline are not yet floating point.)
  • Your app can now supply audio data as a ByteBuffer, in the same format as provided by MediaCodec.
  • The WRITE_NON_BLOCKING option can simplify buffering and multithreading for some apps.

Media playback control

Use the new notification and media APIs to ensure that the system UI knows about your media playback and can extract and show album art. Controlling media playback across a UI and a service is now easier with the new MediaSession andMediaController classes.
The new MediaSession class replaces the deprecated RemoteControlClient class and provides a single set of callback methods for handling transport controls and media buttons. If your app provides media playback and runs on the AndroidTV or Wear platform, use the MediaSession class to handle your transport controls using the same callback methods.
You can now build your own media controller app with the new MediaController class. This class provides a thread-safe way to monitor and control media playback from your app's UI process. When creating a controller, specify aMediaSession.Token object so that your app can interact with the given MediaSession. By using theMediaController.TransportControls methods, you can send commands such as play()stop()skipToNext(), and setRating() to control media playback on that session. With the controller, you can also register aMediaController.Callback object to listen for metadata and state changes on the session.
In addition, you can create rich notifications that allow playback control tied to a media session with the newNotification.MediaStyle class.

Media browsing

Android 5.0 introduces the ability for apps to browse the media content library of another app, through the newandroid.media.browse API. To expose the media content in your app, extend the MediaBrowserService class. Your implementation of MediaBrowserService should provide access to a MediaSession.Token so that apps can play media content provided through your service.
To interact with a media browser service, use the MediaBrowser class. Specify the component name for a MediaSessionwhen you create an MediaBrowser instance. Using that browser instance, your app can then connect to the associated service and obtain a MediaSession.Token object to play content exposed through that service.

Storage


Directory selection

Android 5.0 extends the Storage Access Framework to let users select an entire directory subtree, giving apps read/write access to all contained documents without requiring user confirmation for each item.
To select a directory subtree, build and send an OPEN_DOCUMENT_TREE intent. The system displays allDocumentsProvider instances that support subtree selection, letting the user browse and select a directory. The returned URI represents access to the selected subtree. You can then use buildChildDocumentsUriUsingTree() andbuildDocumentUriUsingTree() along with query() to explore the subtree.
The new createDocument() method lets you create new documents or directories anywhere under the subtree. To manage existing documents, use renameDocument() and deleteDocument(). Check COLUMN_FLAGS to verify provider support for these calls before issuing them.
If you're implementing a DocumentsProvider and want to support subtree selection, implement isChildDocument() and include FLAG_SUPPORTS_IS_CHILD in your COLUMN_FLAGS.
Android 5.0 also introduces new package-specific directories on shared storage where your app can place media files for inclusion in MediaStore. The new getExternalMediaDirs() returns paths to these directories on all shared storage devices. Similarly to getExternalFilesDir(), no additional permissions are needed by your app to access the returned paths. The platform periodically scans for new media in these directories, but you can also use MediaScannerConnectionto explicitly scan for new content.

Wireless & Connectivity


Multiple network connections

Android 5.0 provides new multi-networking APIs that let your app dynamically scan for available networks with specific capabilities, and establish a connection to them. This functionality is useful when your app requires a specialized network, such as an SUPL, MMS, or carrier-billing network, or if you want to send data using a particular type of transport protocol.
To select and connect to a network dynamically from your app, follow these steps:
  1. Create a ConnectivityManager.
  2. Use the NetworkRequest.Builder class to create an NetworkRequest object and specify the network features and transport type your app is interested in.
  3. To scan for suitable networks, call requestNetwork() or registerNetworkCallback(), and pass in theNetworkRequest object and an implementation of ConnectivityManager.NetworkCallback. Use therequestNetwork() method if you want to actively switch to a suitable network once it’s detected; to receive only notifications for scanned networks without actively switching, use the registerNetworkCallback() method instead.
When the system detects a suitable network, it connects to the network and invokes the onAvailable() callback. You can use the Network object from the callback to get additional information about the network, or to direct traffic to use the selected network.

Bluetooth Low Energy

Android 4.3 introduced platform support for Bluetooth Low Energy (Bluetooth LE) in the central role. In Android 5.0, an Android device can now act as a Bluetooth LE peripheral device. Apps can use this capability to make their presence known to nearby devices. For instance, you can build apps that allow a device to function as a pedometer or health monitor and communicate its data with another Bluetooth LE device.
The new android.bluetooth.le APIs enable your apps to broadcast advertisements, scan for responses, and form connections with nearby Bluetooth LE devices. To use the new advertising and scanning features, add theBLUETOOTH_ADMIN permission in your manifest. When users update or download your app from the Play Store, they are asked to grant the following permission to your app: "Bluetooth connection information: Allows the app to control Bluetooth, including broadcasting to or getting information about nearby Bluetooth devices."
To begin Bluetooth LE advertising so that other devices can discover your app, call startAdvertising() and pass in an implementation of the AdvertiseCallback class. The callback object receives a report of the success or failure of the advertising operation.
Android 5.0 introduces the ScanFilter class so that your app can scan for only the specific types of devices it is interested in. To begin scanning for Bluetooth LE devices, call startScan() and pass in a list of filters. In the method call, you must also provide an implementation of ScanCallback to report when a Bluetooth LE advertisement is found.

NFC enhancements

Android 5.0 adds these enhancements to enable wider and more flexible use of NFC:
  • Android Beam is now available in the share menu.
  • Your app can invoke the Android Beam on the user’s device to share data by calling invokeBeam(). This avoids the need for the user to manually tap the device against another NFC-capable device to complete the data transfer.
  • You can use the new createTextRecord() method to create an NDEF record containing UTF-8 text data.
  • If you are developing a payment app, you now have the ability to register an NFC application ID (AID) dynamically by calling registerAidsForService(). You can also use setPreferredService() to set the preferred card emulation service that should be used when a specific activity is in the foreground.

Project Volta


In addition to new features, Android 5.0 emphasizes improvements in battery life. Use the new APIs and tool to understand and optimize your app’s power consumption.

Scheduling jobs

Android 5.0 provides a new JobScheduler API that lets you optimize battery life by defining jobs for the system to run asynchronously at a later time or under specified conditions (such as when the device is charging). Job scheduling is useful in such situations as:
  • The app has non-user-facing work that you can defer.
  • The app has work you'd prefer to do when the unit is plugged in.
  • The app has a task that requires network access or a Wi-Fi connection.
  • The app has a number of tasks that you want to run as a batch on a regular schedule.
A unit of work is encapsulated by a JobInfo object. This object specifies the scheduling criteria.
Use the JobInfo.Builder class to configure how the scheduled task should run. You can schedule the task to run under specific conditions, such as:
  • Start when the device is charging
  • Start when the device is connected to an unmetered network
  • Start when the device is idle
  • Finish before a certain deadline or with a minimum delay
For example, you can add code like this to run your task on an unmetered network:
JobInfo uploadTask = new JobInfo.Builder(mJobId,
                                         mServiceComponent /* JobService component */)
        .setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED)
        .build();
JobScheduler jobScheduler =
        (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(uploadTask);
If the device has stable power (that is, it has been plugged in for more than 2 minutes and the battery is at a healthy level), the system will run any scheduled job that is ready to run, even if the job’s deadline has not expired.
To see an example of how to use the JobScheduler API, refer to the JobSchedulerSample implementation sample in this release.

Developer tools for battery usage

The new dumpsys batterystats command generates interesting statistical data about battery usage on a device, organized by unique user ID (UID). The statistics include:
  • History of battery related events
  • Global statistics for the device
  • Approximate power use per UID and system component
  • Per-app mobile ms per packet
  • System UID aggregated statistics
  • App UID aggregated statistics
Use the --help option to learn about the various options for tailoring the output. For example, to print battery usage statistics for a given app package since the device was last charged, run this command:
$ adb shell dumpsys batterystats --charged <package-name>
You can use the Battery Historian tool on the output of the dumpsys command to generate an HTML visualization of power-related events from the logs. This information makes it easier for you to understand and diagnose any battery related issues.

Android in the Workplace and in Education


Managed provisioning

Android 5.0 provides new functionality for running apps within an enterprise environment. A device administrator can initiate a managed provisioning process to add a copresent but separate managed profile to a device, if the user has an existing personal account. Apps that are associated with managed profiles appear alongside non-managed apps in the user’s Launcher, recents screen, and notifications.
To start the managed provisioning process, send ACTION_PROVISION_MANAGED_PROFILE in an Intent. If the call is successful, the system triggers the onProfileProvisioningComplete() callback. You can then callsetProfileEnabled() to enable this managed profile.
By default, only a small subset of apps are enabled in the managed profile. You can install additional apps in the managed profile by calling enableSystemApp().
If you are developing a Launcher app, you can use the new LauncherApps class to get a list of launchable activities for the current user and any associated managed profiles. Your Launcher can make the managed apps visually prominent by appending a work badge to the icon drawable. To retrieve the badged icon, call getUserBadgedIcon().
To see how to use the new functionality, refer to the BasicManagedProfile implementation sample in this release.

Device owner

Android 5.0 introduces the ability to deploy a device owner app. A device owner is a specialized type of device administrator that has the additional ability to create and remove secondary users and to configure global settings on the device. Your device owner app can use the methods in the DevicePolicyManager class to take fine-grain control of the configuration, security, and apps on managed devices. A device can have only one active device owner at a time.
To deploy and activate a device owner, you must perform an NFC data transfer from a programming app to the device while the device is in its unprovisioned state. This data transfer sends the same information as in the provisioning intent described in Managed provisioning.

Screen pinning

Android 5.0 introduces a new screen pinning API that lets you temporarily restrict users from leaving your task or being interrupted by notifications. This could be used, for example, if you are developing an education app to support high stakes assessment requirements on Android, or a single-purpose or kiosk application. Once your app activates screen pinning, users cannot see notifications, access other apps, or return to the home screen, until your app exits the mode.
There are two ways to activate screen pinning:
  • Manually: Users can enable screen pinning in Settings > Security > Screen Pinning, and select the tasks they want to pin by touching the green pin icon in the recents screen.
  • Programmatically: To activate screen pinning programmatically, call startLockTask() from your app. If the requesting app is not a device owner, the user is prompted for confirmation. A device owner app can call thesetLockTaskPackages() method to enable apps to be pinnable without the user confirmation step.
When task locking is active, the following behavior happens:
  • The status bar is blank, and user notifications and status information are hidden.
  • The Home and Recent Apps buttons are hidden.
  • Other apps cannot launch new activities.
  • The current app can start new activities, as long as doing so does not create new tasks.
  • When screen pinning is invoked by a device owner, the user remains locked to your app until the app callsstopLockTask().
  • If screen pinning is activity by another app that is not a device owner or by the user directly, the user can exit by holding both the Back and Recent buttons.

Printing Framework


Render PDF as bitmap

You can now render PDF document pages into bitmap images for printing by using the new PdfRenderer class. You must specify a ParcelFileDescriptor that is seekable (that is, the content can be randomly accessed) on which the system writes the the printable content. Your app can obtain a page for rendering with openPage(), then call render() to turn the opened PdfRenderer.Page into a bitmap. You can also set additional parameters if you only want to convert a portion of the document into a bitmap image (for example, to implement tiled rendering to zoom in on the document).
For an example of how to use the new APIs, see the PdfRendererBasic sample.

System


App usage statistics

You can now access app usage history on an Android device with the new android.app.usage API. This API provides more detailed usage information than the deprecated getRecentTasks() method. To use this API, you must first declare the "android.permission.PACKAGE_USAGE_STATS" permission in your manifest. The user must also enable access for this app through Settings > Security > Apps with usage access.
The system collects the usage data on a per-app basis, aggregating the data over daily, weekly, monthly, and yearly intervals. The maximum duration that the system keeps this data is as follows:
  • Daily data: 7 days
  • Weekly data: 4 weeks
  • Monthly data: 6 months
  • Yearly data: 2 years
For each app, the system records the following data:
  • The last time the app was used
  • The total length of time the app was in the foreground for that time interval (by day, week, month, or year)
  • Timestamp capturing when a component (identified by a package and activity name) moved to the foreground or background during a day
  • Timestamp capturing when a device configuration changed (such as when the device orientation changed because of rotation)

Testing & Accessibility


Testing and accessibility improvements

Android 5.0 adds the following support for testing and accessibility:
  • The new getWindowAnimationFrameStats() and getWindowContentFrameStats() methods capture frame statistics for window animations and content. These methods let you write instrumentation tests to evaluate whether an app is rendering frames at a sufficient refresh frequency to provide a smooth user experience.
  • The new executeShellCommand() method lets you execute shell commands from your instrumentation test. The command execution is similar to running adb shell from a host connected to the device, allowing you to use shell-based tools such as dumpsysamcontent, and pm.
  • Accessibility services and test tools that use the accessibility APIs (such as UiAutomator) can now retrieve detailed information about the properties of windows on the screen that sighted users can interact with. To retrieve a list ofAccessibilityWindowInfo objects, call the new getWindows() method.
  • The new AccessibilityNodeInfo.AccessibilityAction class lets you define standard or customized actions to perform on an AccessibilityNodeInfo. The new AccessibilityNodeInfo.AccessibilityAction class replaces the actions-related APIs previously found in AccessibilityNodeInfo.
  • Android 5.0 provides finer-grain control over text-to-speech synthesis in your app. The new Voice class allows your app to use voice profiles associated with specific locales, quality and latency rating, and text-to-speech engine-specific parameters.

IME


Easier switching between input languages

Beginning in Android 5.0, users can more easily switch between all input method editors (IME) supported by the platform. Performing the designated switching action (usually touching a Globe icon on the soft keyboard) cycles through all such IMEs. This change in behavior is implemented by the shouldOfferSwitchingToNextInputMethod() method.
In addition, the framework now checks whether the next IME includes a switching mechanism at all (and, thus, whether that IME supports switching to the IME after it). An IME with a switching mechanism will not cycle to an IME without one. This change in behavior is implemented by the switchToNextInputMethod() method.
To see an example of how to use the updated IME-switching APIs, refer to the updated soft-keyboard implementation sample in this release. To learn more about how to implement switching between IMEs, see Creating an Input Method.

Manifest Declarations


Declarable required features

The following values are now supported in the <uses-feature> element, so you can ensure that your app is installed only on devices that provide the features your app needs.

User permissions

The following permission is now supported in the <uses-permission> element to declare the permissions your app requires to access certain APIs.
  • BIND_DREAM_SERVICE: When targeting API level 21 and higher, this permission is required by a Daydream service, to ensure that only the system can bind to it.

Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in theCreative Commons 2.5 Attribution License.

Original Page Direct link:
http://developer.android.com/about/versions/android-5.0.html

Android 5.1 APIs

Android 5.1 APIs

API Level: 22
Android 5.1 (LOLLIPOP_MR1) is an update to the Lollipop release that offers new features for users and app developers. This document provides an introduction to the most notable new APIs.
For a high-level look at the new platform features, see the Android Lollipop highlights.

Update your target API level

To start building apps for Android 5.1, use the SDK Manager to download the Android 5.1 SDK Platform and System Images. Then set your app development project to use a targetSdkVersion of "22". Install your app on an Android 5.1 system image, test it, then publish the updated app with this change.
You can use Android 5.1 APIs while also supporting older versions by adding conditions to your code that check for the system API level before executing APIs not supported by your minSdkVersion. To learn more about maintaining backward compatibility, read Supporting Different Platform Versions.
For more information about how API levels work, read What is API Level?

Multiple SIM Card Support


Android 5.1 adds support for using more than one cellular carrier SIM card at a time. This feature lets users activate and use additional SIMs on devices that have two or more SIM card slots.
You can access information about the currently active SIM through the SubscriptionManager class, including whether or not the device is considered to be roaming on the current network. This information is useful for developers who want to throttle their apps' data access down or off for device users who are sensitive to data access charges. Your app can be alerted to changes in a device's current network connection by requesting the READ_PHONE_STATE permission and settingSubscriptionManager.OnSubscriptionsChangedListener on the SubscriptionManager object.

Deprecated HTTP Classes


The org.apache.http classes and the android.net.http.AndroidHttpClient class have been deprecated in Android 5.1. These classes are no longer being maintained and you should migrate any app code using these APIs to theURLConnection classes as soon as possible.

Carrier Services


Android 5.1 provides support for telecommunication service providers to create apps that can perform carrier provisioning tasks on an Android device. These APIs provide a secure and flexible way for carrier-developed apps to perform these tasks and be distributed through Google Play. Apps that use these functions must be signed by a certificate that matches the certificate in the device's Universal Integrated Circuit Card (UICC).
The carrier service APIs have been added to the TelephonyManager class, the SmsManager class, and the newCarrierMessagingService class. Apps can check for access to these APIs by calling the hasCarrierPrivileges()method. Apps that call these APIs without access receive a SecurityException.

Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in theCreative Commons 2.5 Attribution License.

Original Page Direct link:
http://developer.android.com/about/versions/android-5.1.html

Android Lollipop

Android Lollipop

Welcome to Android 5.0 Lollipop—the largest and most ambitious release for Android yet!
This release is packed with new features for users and thousands of new APIs for developers. It extends Android even further, from phones, tablets, and wearables, to TVs and cars.
For a closer look at the new developer APIs, see the Android 5.0 API Overview. Or, read more about Android 5.0 for consumers at www.android.com.

Material design
Android_Lollipop
Note: The Android 5.1 Lollipop MR1 update is available with additional features and fixes. For more information, see the Android 5.1 API Overview.

Android 5.0 brings Material design to Android and gives you an expanded UI toolkit for integrating the new design patterns easily in your apps.
New 3D views let you set a z-level to raise elements off of the view hierarchy and cast realtime shadows, even as they move.
Built-in activity transitions take the user seamlessly from one state to another with beautiful, animated motion. The material theme adds transitions for your activities, including the ability to use shared visual elements across activities.

You can also define vector drawables in XML and animate them in a variety of ways. Vector drawables scale without losing definition, so they are perfect for single-color in-app icons.Ripple animations are available for buttons, checkboxes, and other touch controls in your app.
A new system-managed processing thread called RenderThread keeps animations smooth even when there are delays in the main UI thread.

Performance focus


Android 5.0 provides a faster, smoother and more powerful computing experience.
Android now runs exclusively on the new ART runtime, built from the ground up to support a mix of ahead-of-time (AOT), just-in-time (JIT), and interpreted code. It’s supported on ARM, x86, and MIPS architectures and is fully 64-bit compatible.
ART improves app performance and responsiveness. Efficient garbage collection reduces the number and duration of pauses for GC events, which fit comfortably within the v-sync window so your app doesn’t skip frames. ART also dynamically moves memory to optimize performance for foreground uses.
Android 5.0 introduces platform support for 64-bit architectures—used by the Nexus 9's NVIDIA Tegra K1. Optimizations provide larger address space and improved performance for certain compute workloads. Apps written in the Java language run as 64-bit apps automatically—no modifications are needed. If your app uses native code, we’ve extended the NDK to support new ABIs for ARM v8, and x86-64, and MIPS-64.
Continuing the focus on smoother performance, Android 5.0 offers improved A/V sync. The audio and graphics pipelines have been instrumented for more accurate timestamps, enabling video apps and games to display smooth synchronized content.

Notifications


Notifications in Android 5.0 are more visible, accessible, and configurable.
Varying notification details may appear on the lock screen if desired by the user. Users may elect to allow none, some, or all notification content to be shown on a secure lock screen.
Key notification alerts such as incoming calls appear in a heads-up notification—a small floating window that allows the user to respond or dismiss without leaving the current app.
You can now add new metadata to notifications to collect associated contacts (for ranking), category, and priority.
A new media notification template provides consistent media controls for notifications with up to 6 action buttons, including custom controls such as "thumbs up"—no more need for RemoteViews!

Your apps on the big screen


Android TV provides a complete TV platform for your app's big screen experience. Android TV is centered around a simplified home screen experience that allows users to discover content easily, with personalized recommendations and voice search.
With Android TV you can now create big, bold experiences for your app or game content and support interactions with game controllers and other input devices. To help you build cinematic, 10-foot UIs for television, Android provides aleanback UI framework in the v17 support library.
The Android TV Input Framework (TIF) allows TV apps to handle video streams from sources such as HDMI inputs, TV tuners, and IPTV receivers. It also enables live TV search and recommendations via metadata published by the TV Input and includes an HDMI-CEC Control Service to handle multiple devices with a single remote.
The TV Input Framework provides access to a wide variety of live TV input sources and brings them together in a single user interface for users to browse, view, and enjoy content. Building a TV input service for your content can help make your content more accessible on TV devices.

Document-centric apps



Document-centric recents.
Android 5.0 introduces a redesigned Overview space (formerly called Recents) that’s more versatile and useful for multitasking.
New APIs allow you to show separate activities in your app as individual documents alongside other recent screens.
You can take advantage of concurrent documents to provide users instant access to more of your content or services. For example, you might use concurrent documents to represent files in a productivity app, player matches in a game, or chats in a messaging app.

Advanced connectivity


Android 5.0 adds new APIs that allow apps to perform concurrent operations with Bluetooth Low Energy (BLE), allowing both scanning (central mode) and advertising (peripheral mode).
New multi-networking features allow apps to query available networks for available features such as whether they are Wi-Fi, cellular, metered, or provide certain network features. Then the app can request a connection and respond to connectivity loss or other network changes.
NFC APIs now allow apps to register an NFC application ID (AID) dynamically. They can also set the preferred card emulation service per active service and create an NDEF record containing UTF-8 text data.

High-performance graphics


Support for Khronos OpenGL ES 3.1 now provides games and other apps the highest-performance 2D and 3D graphics capabilities on supported devices.
Gameloft's Rival Knights uses ASTC (Adaptive Scalable Texture Compression) from AEP and Compute Shaders from ES 3.1 to deliver HDR (High Dynamic Range) Bloom effects and provide more graphical detail.
OpenGL ES 3.1 adds compute shaders, stencil textures, accelerated visual effects, high quality ETC2/EAC texture compression, advanced texture rendering, standardized texture size and render-buffer formats, and more.
Android 5.0 also introduces the Android Extension Pack(AEP), a set of OpenGL ES extensions that give you access to features like tessellation shaders, geometry shaders, ASTC texture compression, per-sample interpolation and shading, and other advanced rendering capabilities. With AEP you can deliver high-performance graphics across a range of GPUs.

More powerful audio


A new audio-capture design offers low-latency audio input. The new design includes: a fast capture thread that never blocks except during a read; fast track capture clients at native sample rate, channel count, and bit depth; and normal capture clients offer resampling, up/down channel mix, and up/down bit depth.
Multi-channel audio stream mixing allows professional audio apps to mix up to eight channels including 5.1 and 7.1 channels.
Apps can expose their media content and browse mediafrom other apps, then request playback. Content is exposed through a queryable interface and does not need to reside on the device.
Apps have finer-grain control over text-to-speech synthesis through voice profiles that are associated with specific locales, quality and latency rating. New APIs also improve support for synthesis error checking, network synthesis, language discovery, and network fallback.
Android now includes support for standard USB audio peripherals, allowing users to connect USB headsets, speakers, microphones, or other high performance digital peripherals. Android 5.0 also adds support for Opus audio codecs.
New MediaSession APIs for controlling media playback now make it easier to provide consistent media controls across screens and other controllers.

Enhanced camera & video


Android 5.0 introduces all new camera APIs that let you capture raw formats such as YUV and Bayer RAW, and control parameters such as exposure time, ISO sensitivity, and frame duration on a per-frame basis. The new fully-synchronized camera pipeline allows you to capture uncompressed full-resolution YUV images at 30 FPS on supported devices.
In addition to giving greater control over image capture, the new APIs also expose detailed information about the camera's properties and capabilities and provide metadata that describes the capture settings of each frame.
Apps sending video streams over the network can now take advantage of H.265 High Efficiency Video Coding (HEVC) for optimized encoding and decoding of video data.
Android 5.0 also adds support for multimedia tunneling to provide the best experience for ultra-high definition (4K) content and the ability to play compressed audio and video data together.

Android in the workplace


Users have a unified view of their personal and work apps, which are badged for easy identification.
To enable bring-your-own-device for enterprise environments, a new managed provisioning process creates a secure work profile on the device. In the launcher, apps are shown with a Work badge to indicate that the app and its data are administered inside of the work profile by an IT administrator.
Notifications for both the personal and work profile are visible in a unified view. The data for each profile is always kept separate and secure from each other, including when the same app is used by both profiles.
For company-owned devices, IT administrators can start with a new device and configure it with a device owner. Employers can issue these devices with a device owner app already installed that can configure global device settings.

Screen capturing and sharing


Android 5.0 lets you add screen capturing and screen sharing capabilities to your app.
With user permission, you can capture non-secure video from the display and deliver it over the network if you choose.

New types of sensors


In Android 5.0, a new tilt detector sensor helps improve activity recognition on supported devices, and a heart rate sensorreports the heart rate of the person touching the device.
New interaction composite sensors are now available to detect special interactions such as a wake up gesture, a pick upgesture, and a glance gesture.

Chromium WebView


The initial release for Android 5.0 includes a version of Chromium for WebView based on the Chromium M37 release, adding support for WebRTCWebAudio, and WebGL.
Chromium M37 also includes native support for all of the Web Componentsspecifications: Custom Elements, Shadow DOM, HTML Imports, and Templates. This means you can use Polymer and its material design elements in a WebView without needing polyfills.
Although WebView has been based on Chromium since Android 4.4, the Chromium layer is now updatable from Google Play.
As new versions of Chromium become available, users can update from Google Play to ensure they get the latest enhancements and bug fixes for WebView, providing the latest web APIs and bug fixes for apps using WebView on Android 5.0 and higher.

Accessibility & input


New accessibility APIs can retrieve detailed information about the properties of windows on the screen that sighted users can interact with and define standard or customized input actions for UI elements.
New Input method editor (IME) APIs enable faster switching to other IMEs directly from the input method.

Tools for building battery-efficient apps


New job scheduling APIs allow you optimize battery life by deferring jobs for the system to run at a later time or under specified conditions, such as when the device is charging or connected to Wi-Fi.
A new dumpsys batterystats command generates battery usage statistics that you can use to understand system-wide power use and understand the impact of your app on the device battery. You can look at a history of power events, approximate power use per UID and system component, and more.

Battery Historian is a new tool to convert the statistics from dumpsys batterystats into a visualization for battery-related debugging. You can find it at https://github.com/google/battery-historian.
Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in theCreative Commons 2.5 Attribution License.

Original Page Direct link:
http://developer.android.com/about/versions/lollipop.html

Monday, 28 September 2015

How to take a screenshot on Galaxy Note 4?

Galaxy Note 4 How-To Guides


How to take a screenshot on Galaxy Note 4?


When you want to show  someone remotely the Galaxy Note 4 screen, e.g., the achievement in a game, booking proofs, ordering info, some key information on a website, location in the Google Map, a Galaxy Note 4 screenshot is the most simple way to deliver such info.
But how to take a screenshot on Galaxy Note 4?
Luckily, there are many different methods to take screenshot on Galaxy Note 4.
In this guide, I will show you 3 different methods of taking a screenshot on Galaxy Note 4 without using any apps, or connecting to other devices. In other words, you can take a  screenshot on Galaxy Note 4 directly. No apps, or connections are involved.

Method 1: Take a screenshot on Galaxy Note 4 with Home and Power button

In the early days,  most Android phones had a hardware home button. The Home button and power button combination is usually for screenshot.
Samsung is a few Android manufactures who refuse to bury hardware home button. So, you can have a simple way to take  a screenshot on Galaxy Note 4.
On any screen, press and hold power button and Home button simultaneously to take a screenshot on Galaxy Note 4.
In the reality, it is hard to press and hold two buttons simultaneously. So this may cause one of the two problems:
  1. Galaxy Note 4 exits current app and return to home screen. This means you press Home button too early.
  2. Galaxy Note 4 shows power options (restart the phone, shutdown the phone..). This means you press Power button too early.
The secret of successfully taking a  screenshot on Galaxy Note 4 is to press and hold the power button “slightly” earlier.
There is a reason for this secret. Home button will response normally within 100ms (about 0.1s) once pressed. But power button only responses usually after 500ms (0.5s).
Using Home button  and Power button to take a screenshot works not only on Galaxy Note 4, but also on almost all Galaxy devices from Samsung.

Method 2:  Take a screenshot on Galaxy Note 4 by swiping your palm over the screen

The second method of taking a screenshot on Galaxy Note 4 may require patience. But it is fun.
You can simply swipe your palm over the Galaxy Note 4 screen as shown below to take a screenshot on Galaxy Note 4.
take-a-screenshot-on-galaxy-note_4-swiping-palm
By default, this feature is turned on. But you may accidentally turned it off if you find this method is not working.
You can enable this feature by following these steps:
Step 1: Go to settings –Motions and gestures.
Step 2: Tap Palm swipe to capture if it is off.
Step 3: Turn it on by drag the switch to right until the color is green.
take-a-screenshot-on-galaxy-note_4_settings-motions-gestures
take-a-screenshot-on-galaxy-note_4_crop_enable-palm-swipe-settings
Again, this palm swiping method of  taking a screenshot on Galaxy Note 4 also works on most other Samsung Galaxy devices.

Method 3:  Take a screenshot on Galaxy Note 4 with S your S Pen using Screen Write (air command)

In old Galaxy Note devcies (Galaxy Note, Galaxy Note 2, Galaxy Note 3, Galaxy Note 8.0, Galaxy Note 10.1, Galaxy Note 10.1 2014 edition and Galaxy Note Pro), you can take a screenshot by  holding the S Pen button, then tapping and holding the S Pen on the screen.
But this S Pen method does NOT work for Galaxy Note 4, due to the new smart select feature in Galaxy Note 4.
Then, can I take a screenshot on Galaxy Note 4 with the S Pen?
Yes, you still can use S Pen to take a screenshot on Galaxy Note 4.  But now you need use one of the four air commands in Galaxy Note 4screen write.
Air command will be launched  when the S Pen  is removed from the slot, or when the S Pen is hovering over any part of the screen with S Pen button pressed.
In the four options of air command, tap screen write to take a screenshot on Galaxy Note 4.
Once the screenshot is taken, you will be offered the options to edit, share, and save the screenshot, as shown below. Tap the check symbol to save the screenshot.
Please note, when screen write is used to take a screenshot on Galaxy Note 4, the editing option is always provided and the screenshot is NOT saved until you tap the check symbol.  This behavior is different from the previous 2 methods.
take-a-screenshot-on-galaxy-note_4_using-screen-write-air-commandtake-a-screenshot-on-galaxy-note_4_using-screen-write-air-command-edit
Screen write was introduced in Galaxy Note 3. So this method also works on Galaxy Note 3, Galaxy Note 10.1 2014 edition and Galaxy Note Pro.

Are there any other methods to take a screenshot on Galaxy Note 4?

Yes, there are some other methods to take a screenshot for Galaxy Note 4.
One of the most common method for all Android devices is throughAndroid debug monitor.  But this required enable some developers options and USB connection with the PC.