There are two ways you can get Kotlin for the Android studio. The simplest way to get Kotlin support is to download Android Studio 3.0 Preview (Canary version). Android Studio 3.0 comes with Kotlin bundled in it. You can keep both earlier version of Android Studio and Android Studio 3.0 side by side. If you don’t want to download Android Studio 3.0 then you can still get Kotlin support by installing the plugin.

Installing Kotlin Plugin for existing Android studio version (which is not a version 3.0) -Go to Android Studio > Preferences > Plugins. You will see the following screenshot. Tap on Install JetBrains plugin button.

Installing Kotlin Plugin for existing Android studio version (which is not a version 3.0) -Go to Android Studio > Preferences > Plugins. You will see the following screenshot. Tap on Install JetBrains plugin button.

Then it will ask you for the plugin to be installed from JetBrains plugins list. As shown in the below screenshot, search for Kotlin and tap on Install button to install Kotlin plugin.

Once the plugin is installed it will ask you to restart the Android studio. Restart it and you have Kotlin plugin in your Android Studio.

We will use Android Studio 3.0 for the “Hello World” program in Kotlin.

Create New Project with Kotlin

You can easily create a new project in Kotlin with few seconds using Android Studio 3.0.

If you have a welcome screen open for Android Studio 3.0 then click on Create new project. You have to then check Include Kotlin Support. Click on Next button to complete project setup.

If you already have Android project open, go to File > New > New Project and follow the same step as mentioned in #1.

Once your project is created, you will see MainActivity with “.kt” extension instead of Java. Your MainActivity code in Kotlin looks like -

If you run the default app, you will see “Hello World!” label displayed at center of the screen. Hola!! You just created your first “Hello world” Android Application in Kotlin. We can go one step further and create button and implement its click listener.

Change Label element in main.xml file to Button and set its text to “Tap me!”.

Finally, an Android developer can say they have some official language to build Android apps. Google has announced official support for Kotlin programming language. We have been using Java for Android apps development ever since (except C++ in NDK) and also struggling to overcome Java issues we have been facing for years. No more fears of NullPointerExceptions!! Kotlin has come to our rescue.

What is Kotlin?

Kotlin is statically typed programming language designed to support multi-platform applications including Java virtual machine (JVM), browsers and Android apps. It runs on JVM. Kotlin was unveiled to the world in 2011 and its first stable version v1.0 was introduced in 2016 after years of development efforts.

Kotlin Features - Kotlin has really cool features.

Conciseness - You don’t have to write boilerplate code in Kotlin as it has pretty concise syntax.

Handling NullPointerExceptions - If you are afraid of unknown NullPointerExceptions, let this worry fade away with Kotlin as this programming language is much safe to avoid entire classes of errors.

Interoperable with other languages - If you are a Java developer or Android developer (where Java is used), Kotlin can be alternative for you as it is 100% interoperable with Java.

Tool-friendly - Kotlin is compatible with Java-based IDEs making it easy to switch to Kotlin.

Why Kotlin support for Android

During Google I/O 2017, Google announced official support for Kotlin programming language for Android development. As mentioned earlier, Kotlin is interoperable with Java, many developers were already using it for Android development and were hoping to get official support from Google. Kotlin has early adoption by many developers like Expedia, Flipboard, Pinterest, Square, and others. Kotlin is chosen for Android due to following facts -

100% interoperable with Java. So you can use both Kotlin and Java in the same app

Easy to use making app development faster

No more NullPointerExceptions at runtime

Smart casting of variables

Destructuring declarations

Importantly supports Lambda functions

Kotlin is bundled with Android Studio 3.0. So you don’t have to worry about adding plugins for Kotlin. Just download Android Studio 3.0 (make sure you get canary version) and get started.

So if you are experienced Android developer, you don’t need to stop using Java immediately but definitely, need to learn Kotlin. If your knowledge lackluster Android development skills, no worries, you can still jump on Android development by starting Kotlin learning.

It’s been around two weeks when Google announced Android O preview. This is again exciting time of the year when you can try out all new features of Android’s upcoming OS version Android - O (what is your guess about ‘O’?) before it is released and keep your apps ready for new OS version support. As it happens with every Android OS version, Android O also brings many new features and some optimizations techniques to make better apps. Here are some of the new features -

Background Limits - A few years back, Android background service implementation was one of the comparison points with iOS. Android Nougat introduced some changes in background service implementation and now with Android O preview, there will be major changes in it. Background service implementation will have certain limitations divided into three major areas viz. implicit broadcasts, background services and location updates. All these changes are introduced to limit background usage and improve interactive performance by improving RAM usage.

Implicit broadcasts -

Apps targeting Android O will no longer receive implicit broadcasts in the background to most manifest declared receivers.

Some of the exceptions to implicit broadcast change will be

BOOT_COMPLETE

LOCALE_CHANGE

USB_DEVICE_ATTACHED etc.

Apps can receive implicit broadcasts only when an app is active.

There is no change in the explicit broadcast that targets application package registered in the manifest. It will work as it is.

Background services -

Android-O puts a limit on how long background service can stay alive once the app goes to background. Background service can now only run for short time after the app has no longer visible activity or any foreground service.

startService or service PendingIntent will throw an IllegalStateException when an app is not in the foreground.

Above mentioned background service changes do not impact foreground services. For example, foreground services which require persistent notifications, work as usual and there is new service to start service in Foreground which is NotificationManager#startServiceInForeground.

There is another catch though, there will be some changes to background services even if your app does not target Android O such as Wakelock will be released when your app enters the cached state where there is no active Android component.

Location updates -

Android play store is flooded with many location-based apps as Android till date supported background location updates. Android-O restricts background location updates. Now your app can request background location updates just a few times per hour.

Location updates in foreground services are not impacted by this change. So apps which do location tracking in real time using foreground service will work as it is.

Your background app can take advantage of another foreground app which is getting location updates. It can then get location updates with the same frequency as that of foreground app.

ANDROID_ID Change - There are some changes in Android ID settings for apps and it will be noticed under Settings.Secure.ANDROID_ID. Prior to Android-O, Settings.Secure.ANDROID_ID was same across all apps but now with Android-O, ANDROID_ID will be different per app per user. This value will persist across app reinstalls. Google still recommend using user-resettable advertising id provided by Google Play service for simple, standard system to help monetize the app

Account Access -

App will not be able to get account access directly using GET_ACCOUNTS permissions. App will have to rely on account choosing activity.

With Android-O, account owners can now choose whether accounts should be visible to other apps. Accordingly, Account choosing activity API will be updated.

Notifications Channel - Android-O adds notifications channel to give a user more control over notifications and app developer more flexibility with notifications to be sent.

The app developer has to use Notification channel for Android O otherwise notifications will not be shown for the app.

Notification channel is named category of notifications from the single app. You can use notification channels to have different categories of notifications.

User can block category or alter its behavior like change importance, add vibrations or lights, an ability to snooze, set timeouts to cancel etc. User can long press on notification to bring out notification channel settings.

Autofill framework - Chrome browser is a well known example where users can avail autofill feature while filling out repetitive information on the web. Android-O introduces Autofill framework so Android apps can make form filling tasks easy to the users.

With Android-O, now user can select autofill app similar to the way keyboard app is selected.

Picture-in-Picture - Picture in Picture (PIP) mode allows your video activity to play in pinned window mode when another foreground activity or app is running. Earlier to Android O, PIP was supported only for Android TVs but now you can use PIP feature in Android O targeted apps on other Android devices as well.

To implement the Picture-in-Picture feature, all app has to do is to call the enterPictureInPictureMode method from resume or pause state of your media activity.

Make sure you continue playback in paused state if you are adding PIP support in your app.

Multi-display support -

Rather than having an app explicitly use the presentation API, regular activities can now be launched on secondary displays.

These displays have per display based configuration and resource management. This means some of the parts of a configuration such as a screen width DP, screen height DP layout, density DP will be set accordingly to the display on which activity currently resides.

Now app developer can get font by just calling the getFont(int) method to get font by ID.

Typeface font = mResources.getFont(R.font.myFont);

You can also declare entire font family in XML file, declaring font style, weight along with font resource.

Connectivity -

Android O will now support Bluetooth CODECS LDAC CODEC.

Wi-Fi Aware is a new feature added in Android-O which was previously known as Neighbor awareness networking (NAN). Devices with required hardware will be able to communicate over Wifi without an Internet access point.

Android-O adds ConnectionService APIs so third-party calling apps can work seamlessly with system UI and other audio apps.

WebView API enhancements - We will see a lot of webView API enhancements to improve app’s stability and security in Android-O. Following set of APIs are introduced in Android-O for webView -

Version API

Google Safe browsing API

Termination Handle API

Renderer Importance API

Pinning shortcuts and widgets - If you are a big fan of 3D touch feature in iOS, you will love pinning shortcut feature of Android-O.

Now app user can access key features of the app directly from app icon from launcher screen.

Developers can pin shortcuts to specific tasks to app icon on launcher screen yet giving control to a user whether to see pinned shortcuts for that or not.

Launcher will show confirmation dialog asking user’s permission to pin the shortcuts. If a user declines, launcher app will not show pinned shortcuts.

Similar to pinned shortcuts, users can pin widgets to the supported launcher.

Just remember, pinned shortcuts and widgets will work on devices running Android-O with launcher supporting pin feature.

Adaptive icons - Android O can now display a variety of shapes for app icons across different device modes. Display of icons depends on OEM mask. Click here for more details about Adaptive icons.

So Android developers, get ready to explore Android-O preview for these and many other features.

Samsung has announced their newest phones Galaxy S8 and Galaxy S8 Plus. Galaxy S8 and Galaxy S8 Plus are one of the largest smartphones of the year.

Samsung Galaxy S8 has a screen size of 148.9 x 68 x 8mm, while the Samsung Galaxy S8 Plus is 159 x 74 x 8mm. So definitely these devices have highest aspect ratio. Galaxy S8 has aspect ratio 18.5:9. As aspect ratio is increased, it is a time to update your app to support maximum aspect ratio to utilize extra space available on the screen. Android APIs has made this task easy. You can support maximum aspect ratio for Android apps by adding following piece of code in the Manifest file of an app. Insert android.max_aspect <meta-data> element in the app’s <application> element

The value of Android.max_aspect should be ratio_float if you want to build an app for maximum supported aspect ratio. You can set float value for this param instead of “ratio_float” if you know maximum aspect ratio your app should be supporting. Please make a note if you do not set the value and if android:resizeableActivity is not true, then the maximum aspect ratio defaults to 1.86 (which is roughly 16:9). So in order to take advantage of extra space available on the screen for larger devices, make sure you are setting a right value for Android.max_aspect.

LG has also announced new phone early this year LG G6 which has aspect ratio of 18:9. So if you want to support newest devices like Samsung Galaxy S8 and LG G6, make sure you declare right elements in the manifest file of your app for the desired aspect ratio support.

Many engineers and researchers from deep learning field must be familiar with TensorFlow platform. Google introduced TensorFlow, an open source system for machine learning in 2015 and yesterday (Feb 15, 2017) at Google’s inaugural TensorFlow Dev Summit in Mountain View, California, they announced a new release of TensorFlow, version 1.0. Before jumping to TensorFlow 1.0 release update, let’s just catch up with what is TensorFlow!

What is TensorFlow?TensorFlow is an open source machine learning library which was initially developed by engineers and researchers at Google Brain Team. Google made it open source in 2015. TensorFlow library can ease the process of applying deep learning algorithms into various areas. Graphical representation of mathematical operations simplifies the deep learning algorithms implementation. It is based on data flow graphs where graph node represents mathematical computations, while the graph edges represent the multidimensional data arrays (which they call as tensors) communicated between them.

What do you need to know before getting started with TensorFlow?

How to code in Python

Mathematical operations at least about Arrays

Some knowledge of machine learning

About TensorFlow 1.0Google claimed that TensorFlow 1.0 is now more production ready than ever, faster than earlier, more flexible and with more stable Python APIs. Many tools have been added to the framework which makes TensorFlow much better.

Faster than earlier: XLA (Accelerated Linear Algebra) now lays a foundation to the optimized TensorFlow v1.0. XLA is domain-specific compiler to speed up TensorFlow computations. It is in an experimental phase (alpha) and one can play with it via Just-in-time (JIT) compilation or ahead-of-time (AOT) compilation. XLA not only speed up the computations but also improves memory usage. Check out XLA details here.

More flexibility: Addition of new APIs and modules like tf.layers, tf.metrics, and tf.losses modules makes TensorFlow more flexible. TensorFlow 1.0 now also compatible with Keras which is another neural network library written in Python.

Python API changes: Changes in major Python APIs which now resembles with NumPy (fundamental scientific Python package for computations) are not backword-compatible. Older programs might not run on TensorFlow 1.0 as expected so this migration guide may come handy to upgrade your programs to V1.0

Java and Go support: TensorFlow 1.0 now adds APIs for Java and Go programming languages (experimental as of now).

TensorFlow Debugger: (tfdbg): TensorFlow 1.0 introduces new command line debugger so develoeprs can now debug live TensorFlow programs.

New Android demos: New demos are created with TensorFlow 1.0 release for Android which showcase object detection and localization, camera-based image stylization.

Integrating Google login in the mobile apps, web apps is a trend! To follow this trend, keeping up with everyday advancing Google’s settings is itself a challenge especially if you are using a third party open source library which uses Google login in it.In the past, I worked on open source K9 mail app to create custom mail app. It allows users to do gmail login. Recently, K9 app started giving me an authentication error even after entering correct gmail credentials.

Googling itself helped me to figure out the solution. It is because a change in the process of using Google authentication within your own app. Most of the apps recently started throwing the same exception as Google marked these apps as a less secure app including Outlook mail app (Ref.https://support.microsoft.com/en-us/kb/2984937). Because these apps might be still using an old process of doing Google login.The best way to get out of this issue is updating your apps, open source libraries with latest Google authentication process. But there is always a workaround to fix something temporarily. So here is the quickest hack-

Think of the feature where activities you perform on mobile app screen is recorded as a video. Screen video recording can be useful in drawing kind of apps where you are recording video of your drawing as you progress.Android SDK comes with many powerful features to implement wide variety of the apps starting from utility apps to enterprise apps. But sometimes it really becomes cumbersome to implement desired feature due to limitation of android OS. Screen video recording feature in the android app is one of them. Android OS has restricted access to mobile screen through any app. There are few applications over Google play store which provide screen video recording feature. But they demand for root access on your device which means your android device has to be rooted to use such applications. If you are developing app for general users then rooting of the device can’t be solution just to have screen video recording feature as not everybody likes to play with their phones by rooting it.

Kitkat 4.4 built in screen video recording feature

Kitkat came with in built screen recording feature using ADB(Android Debug Bridge). But it does not serve above mentioned requirement as screen recording is done from the command line. This can be useful when you only have to create screen recording video for complete application to show how does app work.

Libraries to create video from images in JAVA/Android

FFMPEG is library which can be integrated in android app using android NDK(native development kit). It needs working android NDK copy to build this. However you can still find already built files which can be imported in you android app source code without NDK using java OpenCV library. Java openCV library is a wrapper for FFMPEG written in java. Java OpenCV can be simplest way to integrate FFMPEG to create video from sequence of images in android app.You can download libraries needed from http://search.maven.org/remotecontent?filepath=org/bytedeco/javacv/0.8/javacv-0.8-bin.zip. You can always look on web for latest version of these jars. Once you download zip from above location, you need to copy javacpp.jar, javacv.jar to your project’s libs folder(project folder/libs). Another required jar is opencv-android-arm.jar. Extract opencv-android-arm.jar to get armeabi folder. Copy this armeabi to your project’s libs folder(project folder/libs).

Creating video from sequence of images stored on SD card

Once you import all required jars into your project. You are all set to start coding to create video from sequence of images. You can find pieces of codes as follows - You need import following packages.

Above code creates video from images stored on SD card in Video_images folder. It creates video and stores created video on SD Card in folder- /Video_images/output/ with video name as current time-stamp with mp4 extension. In above code you can choose your own frame rate using following line -

recorder.setFrameRate(1);

If you have large number of images to create video then you can set higher frame rate. But drawback of this method is this method takes time to create video and save it on SD Card.

Using above method in drawing like app to create video of screen drawing

If you want to use above method in drawing like app to capture drawing video best way would be to capture images of parent layout per second and store on SD card. You can initiate this process when user clicks on start recording button. When user clicks on stop recording, you can stop capturing images and call above method providing path of your temporary folder where you saved captured images.Hope this helps you to create video of screen recording without rooting your device!

Are you stuck with above two lines while building your android app? Yes this happens when you are building large application which has added many references libraries in your code.Before moving forward to check solutions for this issue, few things which one should know about why this issue occurs.

Why this issue occurs :

As you go on building large applications, your code size reaches certain limit for total number of methods in the app. Total number of methods referenced by the app does not only include methods written by you but also include methods bundled in external jars, library files which you have added into your project. You must be knowing architecture of android app (APK) which internally contains bytecode files in the form on Dalvik executable (DEX) files. Android has put an upper limit on total number of methods referenced by a single DEX file and which is 65536.Now you can see 65536 in error which you are getting which itself signifies DEX file of your APK has referenced more than 65536 methods. And this is why issue - Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536 occurs in your code.

Avoiding reaching 65536 method limit

Taking few cautious decisions and careful thinking while writing your code since beginning can save you. Always check you are not keeping any unused code in code files. Whenever you are adding any third party lib, you use most of the library functions instead of adding your own. Make sure you do not add any large lib just for couple of methods.Reusable, neat and clean code and proper architecture of project can help you to avoid reaching 65536 methods limit.

How to resolve?

Android architecture has also provided solution to resolve this issue. Multidex files is the one solution which you can use to resolve issue of 65536 methods limit. But there are other simple approaches which one can use to resolve this issue. I will discuss multidex file support sometime later in another post. Let’s see initial step towards resolving issue i.e ProGuard

ProGuard Configuration :

Android has provided ProGuard tool which optimizes your code by removing unused code, methods. This reduces size of your app (APK). By default ProGuard configuration is not enabled when you create Android project. One can configure ProGuard by following few steps.

ProGuard tool is found in your SDK path at {SDK_FOLDER}/tools/proguard/

Above mentioned ProGuard folder from SDK has proguard-android.txt which plays major role when you enable ProGuard setting for your project

Open project.properties file in edit mode (any simple editor will suffice) which will be in your project folder

This line must be preceded with # (# is to comment whole line in project.properties file). Un comment this line by removing preceded #. Your SDK path has to be set in environment variables.

Your configuration is done. Clean the code, build it and run it. If it runs successfully you must see proguard.txt file in bin folder of your project.

After configuring ProGuard, if app still shows same issue of 65536 limit you can try un checking Private Libraries from build path in project properties. Please see below screen shot for reference.After this step again clean the code, build and run the app

ProGuard is not full proofed solution to resolve 65K methods limit. However ProGuard will resolve the issue if DEX file from reduced size APK contains methods less than 65K after shrinking, obfuscation of code and removal of unusedcode code by ProGuard tool. If final DEX file still references more than 65536 method then one may have to go for multi DEX solution!

Being an android developer and a project manager in most of the projects, got opportunity to work in depth on advertisement platforms integration in mobile app. Integration of ad platform in mobile app is simplest and easiest way to start monetization. Experience of working with different ad platforms made me thought about questions which one should ask before they choose ad platform to start revenue through their mobile apps.

What kind of ads do you want to show in your mobile app?

Ad platforms have introduced many flavors of ads to be shown through the mobile apps. Few of them are

Banner ads -

Ad displayed in the form of banner either on top/bottom of the mobile app.

One should verify available sizes of banner for particular ad platform. Because sometimes banner ad appears at the center of the device irrespective of device’s size. It does not fill complete width of the device. One should be concerned about this if UI of the screen is one of the major concerns

One can make money out of banner ads if they provide a feature to purchase an app to see ads free version. As banner ads appears on every screen user might like to buy ads free version.

Check if banner ads are available for phones, tablets etc. in case of android as it comes with wide range of devices in terms of the size

Interstitial ads -

Ads displayed in the form of full screen which can be popped up sometimes when user is going through the app.

Preferred for games or gaming kind of apps.

Native ads

Native ads are kind of ads which can be shown in between your list items which more or less will look like your list items.

These ads come with action buttons like “Install”, “Download” etc.

These can be shown after every set of your own list items.

Flexible enough to fit into your own list view UI

Video ads

Videos are shown in the full screen.

These can work best if you are developing some kind of videos apps.

Here are the questions to be asked to yourself before you choose or integrate ads network

What all kinds of ads I want to integrate in my mobile app?

Have I done enough research about target ad platform I am going to integrate?

What is fill rate of type of ad for this particular ad platform?

Can I integrate different ad platform through some mediation platform?

If I am planning to integrate particular ad platform as a mediation for third party ad networks, how many and which ad networks can be route through this?

Does ad platform has proper and well documentation for integration guide (this is also important otherwise most of the time you can end up in things not working as the way you expected them).

Does ad platform provide in house ads feature? (In house ads are your own customized ads or ads for your other apps or maybe for the publishers who are ready to show their ads through your app)

Does target ad platform has enough ads available on their marketplace for the country or region your app is targeting? (Most of the ad platform works better in US but does not seem to work in India)

Do I need random ads from ad platform? Or do I need to filter ads depending on criteria by age group, location or categories etc.?(ad platform allows to set many parameters to filter out ads. One can avoid this as it might reduce ads fill rate.)

Have I checked terms and conditions for ad platform integration whether I am fulfilling criteria or not? Chances of skipping this step are higher if any third party developer is taking care of setting up an ad platform account on behalf of you for your mobile app.

Have I checked terms and conditions for payment system for withdrawing revenue from ad platform integrated?

Importantly, have I made sure that my ad integration won’t annoy target audience and it will give better user experience yet earning enough from ads integration?Above checklist may add or remove few questions as this may vary with ad platforms. However asking few questions before you choose or integrate any ad platform into your mobile app and putting some well planned algorithm in place may turn into good monetization strategy for your app.

To test ad platform integration one might go for live ads and these can get number of hits knowingly or unknowingly which ad platform provider might think as spamming. And your ad platform account might get blocked. So make sure you test live ads yet avoid unnecessary hits on it to get into hassle of account blocking.

If you are looking to experience Google Glass without actually buying such a expensive device, then you can simply download some apks which can turn your Android device into Google Glass.Android device can be made to function like Google glass by installing few apks.Found two links which gives step by step guideline to do this.

Steps to make your device to function like Glass

Install all the apks available on #1 link mentioned above.

Do not open any of the app after installation.

Login to https://accounts.google.com/myglass to setup your glass. Follow all steps here. It might fail at step to connect to your wi-fi. It worked for me after several retry.4. Open Glass home app installed in #1 link.

You can see Glass on your Android device.

My observations about this simulated Glass

One can use Mirror APIs to push cards (static or live cards) from cloud/web on this simulated glass.2. You will see few commands on next screen when you say “ok glass” from home screren.

Camera and other few options does not work. It crashes.4. One can see how menu options works for Google glass app using Google search feature which you see on this simulated glass.Google search is opened when double tapped on glass home screen. Pages seen from Google search are later shown in past cards of glass timeline when you swipe right to left from home screen.

I created one simple hello world application for Google glass. Tried to run this application on Android device which is now simulated Glass. Here are my observations for this test.

It could not install any glass application on this simulated Glass. As Glass application source code mentions

When tried to run app by setting android:required (in manifest of hello world glass app)field to false for above uses-library, it gives another exception for class not found for classes of GDK.

When tried another way to install app by adding gdk.jar from add-on from Android sdk setup, it gives another exception.

So even though this simulated glass is not much useful for glass development, but it definitely gives quick feel to Google glass if you just want to see how Glass works without paying for Google Glass.