Android Language Highlights A Developers Perspective

Although Web applications are important and widely used these days, but there are several reasons why native applications are sometimes preferable for mobile apps.

 

  • You can use graphics and UI controls that are not available in browsers.
  • You can customize the apps for small screen sizes.
  • You can use resources (location, address book, phone, network, local database) that are unavailable in Web-based applications.

 

Android is the preferred platform for building corporate apps since you can install Android apps from your company Web site, rather than submitting them to the Apple App Store as required for the iPhone. Here I am writing about what is android in very brief and then I will come up with the language highlights.

Android is an open source and Linux-based operating system for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies. It is one of the most widely used operating system for mobile these days. Today in this post I will be giving you highlights on android’s features from a developer’s view.

Generally when you write android code below is the most usual part of code you will find in every android app.

 

 

Android itself is a complete language and it does not require any other 3rd party language to create and develop applications on it. Readers and developer sometime get the wrong assumption on the language. The APIs in android are written in the java language is you use the SDK and c++ if you use NDK. You should have some basic knowledge of these languages if you want to start with android but it;s not must. You can start working with android even if you don’t know the basics of Java and c++. Learning android is very simple and easy.

 

Today I am not going to teach you how to get started with Android. J Instead, I will give you some hints and highlights on android keeping a developer’s view in my mind.

From its first version to the latest i.e. 5.1 Android introduced, updated and added lots of new features and APIs. Today I will give you some Highlights on this all together, keeping just android in my mind.

From 3D views to managed provisioning processes, there’s a lot for Android developers which they will love about the new Lollipop version.

 3D views and real-time shadows

Android introduces elevation property to give apps an added dimension. Now you can set the new elevation property for graphical objects in an Android 5 application using the android: elevation property. This will enable real-time shadows beneath the object to create the illusion that it’s floating above the background. See the code snippet below:

 

 

And the background can be defined as a rectangle to imply the shadow effect.

 

 

Another way to change elevation is with the new setTranslationZ method of views, for example view.setTranslationZ(120); you can animate elevation changes with the new ViewPropertyAnimator.z() and ViewPropertyAnimator.translationZ() methods.

 

Activity transitions

With the release of Android 5 developers get the gift of new Transitions API for activity transitions. With this new API, we can animate transitions between activities by finding their view IDs, creating an Intent and a Bundle of views to define a scene transition animation, and passing them to startActivity(), as shown in the code below. The Lollipop system takes care of rendering the actual transition animation.

 

 

Heads-up notifications

 Now with Android 5 developers can take the notifications to the next level, including the ability to create “heads-up notifications,” floating alerts that can be acted on or swept away without leaving the current, full-screen app.

The code below shows a Lollipop head-up notification of an incoming phone call, displayed over a text view. The following code snippet shows how a heads-up notification is set up:

 

This version of android also allows developers with more control over lock-screen notifications, for example to mark certain information as private. That’s set with values ofNotificationVisibility, such as NotificationVisibility.SECRET.

 

Concurrent documents

The overview screen, or the “resents” screen, is a system-level UI that shows a list of recently opened activities and tasks. In Android 5, multiple instances of the same activity containing different documents may appear as tasks on the overview screen, thereby allowing users easy access to more of what your app offers. Although developers should always allow the system to define how their tasks and activities are represented in the overview screen, but they can use the flags of the Intent class to specify whether an activity is to be added or removed from the overview screen.

 

Bluetooth Low Energy scanning and advertising

The new APIs added in Android 5 are like a boom for developers. They allow apps to perform concurrent operations with BLE (Bluetooth Low Energy), allowing both scanning (central mode) and advertising (peripheral mode). BLE is getting popular these days because they seem perfect to use in health and fitness applications, as it is aimed at greatly reducing the power usage of Bluetooth, while delivering similar performance and functionality.

You can see the methods described below or you can browse them on android developer’s site to see how your app can start and stop its Bluetooth LE advertising activity. To find BLE devices, you must use the BluetoothAdapter.startLeScan() method.

 

void startAdvertising (AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseCallback callback)

Start Bluetooth LE Advertising. On success, the advertiseData will be broadcasted. Returns immediately, the operation status is delivered through callback.

Requires BLUETOOTH_ADMIN permission.

Parameters

settings – Settings for Bluetooth LE advertising.

advertiseData – Advertisement data to be broadcasted.

callback – Callback for advertising status.

 

void startAdvertising (AdvertiseSettings settings, AdvertiseData advertiseData, AdvertiseData scanResponse, AdvertiseCallbackcallback)

Start Bluetooth LE Advertising. The advertiseData will be broadcasted if the operation succeeds. The scanResponse is returned when a scanning device sends an active scan request. This method returns immediately, the operation status is delivered through callback.

Requires BLUETOOTH_ADMIN

Parameters

settings – Settings for Bluetooth LE advertising.

advertiseData – Advertisement data to be advertised in advertisement packet.

scanResponse – Scan response associated with the advertisement data.

callback – Callback for advertising status.

public void stopAdvertising (AdvertiseCallback callback)

Stop Bluetooth LE advertising. The callback must be the same one use in startAdvertising(AdvertiseSettings, AdvertiseData, AdvertiseCallback).

Requires BLUETOOTH_ADMIN permission.

Parameters

Callback – AdvertiseCallback identifies the advertising instance to stop.

 

OpenGL ES and Android Extension Pack

OpenGL ES has been added to android from its first version to ease the developers improve their games and performance. Now Android 5 has introduced OpenGL ES 3.1 and the Android Extension Pack which offers android programmers very high-performance 2D and 3D graphics APIs.

The latest version of OpenGL ES is now capable to compute shaders, stencil textures, accelerated visual effects, advanced texture rendering, tessellation shaders, geometry shaders, ASTC texture compression, and per-sample interpolation and shading. OpenGL APIs work across different brands of GPU; the ES designation refers to the OpenGL standard for embedded systems.

MediaBrowser and MediaSession APIs

Android allows apps to browse the media content libraries of other apps through the android.media.browse API. The content must be exposed by the app via the MediaBrowserService class. This API is all about apps integrating with each other, using the same UIs, and avoiding the need to duplicate existing services.

In addition, the MediaSession class replaces the deprecatedRemoteControlClient class and provides a single set of callback methods for handling transport controls and media buttons. It allows developer to interact with media controllers, volume keys, media buttons and transport controls. As stated in API reference A MediaSession should be created when an app wants to publish media playback information or handle media keys. In general an app only needs one session for all playbacks, though multiple sessions can be created to provide finer grain controls of media.”

Following code snippet shows how you can create a mediaplayerservice using MediaSession:

 

New camera APIs with RAW support

Many photographers or I should say the serious photographers always love RAW image formats because they offer a higher dynamic range, fewer artifacts, and more post processing flexibility than compressed JPEG formats.

Until now, in android, RAW formats were not available for Android device cameras. The code below demonstrates how to capture an image from the Android camera device in JPEG format and create them in RAW format. The new camera2 class, parent of the CameraDevice class introduced in Android 5 supports the RAW_SENSOR image format, which allows developers to write the received RAW pixel data in the standard Adobe DNG (Digital Negative) format.

 

Screen capturing and sharing

Early versions of Android had no easy way to take screenshots; developers had to install the SDK and use the debugger, which was not so easy because of the necessary device drivers were hard to locate. With the incremental growth of the Android, developers could install a third-party screenshot app, but still they had to root the device. And then finally, most Android devices have supported at least one way to generate a screenshot using some UI; for example, few devices use a combination press of the down toggle and the power button.

In Android 5, apps can initiate screen captures themselves. Developers now will be able to do this by first calling Context.getSystemService() with the argument MEDIA_-PROJECTION_SERVICE to get a MediaProjectionManager class instance; then call, callcreateScreenCaptureIntent () to get an Intent; then, pass the Intent tostartActivityForResult() to start the screen capture; and finally, pass the result togetMediaProjection() to get the capture data.

Managed provisioning process for workplace security

Up until now, Android hasn’t had a very good out-of-the-box security story for work use as compared to BlackBerry and iOS. A new managed provisioning process creates a secure work profile of the device; in the launcher, apps are shown with a Work badge. An IT administrator takes care of work apps and their data inside of the work profile. To implement this try the code below:

 

You can go further and deploy and activate a device owner prior to provisioning, using an NFC data transfer from a programming app. A device owner app can use the methods in the DevicePolicyManager class to take fine-grain control of the configuration, security, and apps on a managed device.

Low-latency audio input

The Android multimedia framework includes support for capturing and encoding a variety of common audio formats, so you can easily integrate audio into your applications. You can record audio using the MediaRecorder APIs if supported by the device hardware. The code snippet below illustrates the use of the Media-Recorder class. The new audio capture design includes a fast capture thread that never blocks except during a read; fast track capture clients at the native sample rate, channel count, and bit depth; and normal capture clients that offer resampling, up/down channel mix, and up/down bit depth.

 

Leanback UI and Android TV Input Frameworks

Last but not least, Android 5 also introduces Leanback, the new UI for TV screens. Developers looking to capitalize on growing interest in Android-based TVs would love to working with this addition.

 

The code snippet above has been taken from developer’s site which shows how to include a LEANBACK_LAUNCHER intent filter in your Android 5 application manifest to ensure your app operates under Leanback when opened on an Android TV. You don’t have to use the Leanback library or any of the other support libraries and frameworks (such as the Android TV Input Framework, aka TIF, which allows TV apps to handle video streams from sources such as HDMI inputs, TV tuners, and IPTV receivers) that have been added for big screens in Lollipop, but it streamlines your code and helps to make your UIs consistent with the guidelines.

Android Cloud to Device Messaging

 This is one feature that’s been sorely lacking from the Android platform. The demo at Google IO demonstrated how you can push a message to a device in real time, and have it fire off an Intent which can kick off any number of interesting and yet to be dreamed of services. This also opens up a new way for devices to communicate with each other in real time over the internet.
Android Application Error Reports

Logging exceptions remotely that occurs on a user’s device is a very useful. The typically way to do it is to override the default exception handler and replace it with something that will log the exception. The initial usefulness of this will be somewhat limited, due to the fact that many devices are going to be running older versions of android for the foreseeable future.

I hope this guide has given you a taste of android language and could create the impression of the strong development environment of android language. If yes, this is not enough and all about the language. You should go on and continue exploring each and every part related to the android app development soon. What I have talked about here are just the highlights. You should learn much more to become a professional developer.

 

Join the EDUMOBILE academy to learn more on android and keep reading me. Thanks

Leave a Comment: