Detect device year class on Android with Facebook Device Year Class

When you make Android applications, it is always useful to know the year class of the running device. Indeed, with that information, you can adapt the behavior of your application to the smartphone or tablet of your users. Obviously, the main goal being to offer them a better experience with your application.

Image for post
Image for post

For that, Facebook offers Device Year Class an Android open source library implementing a simple algorithm which maps a device’s RAM, CPU cores and clock speed to the year where those combination of specifications were considered high end.

It allows you to easily modify the behavior of your Android application according the capabilities of the phone’s hardware. The mapping used by the algorithm of Facebook Device Year Class is based on the following table :

Image for post
Image for post

In this tutorial, you are going to discover how it is simple to use Facebook Device Year Class Library in your Android applications to detect the probable year class of the running phone.

You can also enjoy directly this tutorial on YouTube in video :

Integration

First step is to integrate Facebook Device Year Class Library in your Android application project. For that, you have just to add the following dependency in your build.gradle file :

Get the year class of the device

Once the library is installed, you can get the year class of the device simply with the following code :

Adapt the behavior of your Android App

With this information, you can modify the behavior of your application with the following snippet of code :

That’s all for that tutorial. To discover more Android tutorials, don’t hesitate to subscribe to the SSaurel’s Channel on YouTube : https://www.youtube.com/user/sylsau/

You can also discover tutorials and articles on the SSaurel’s Blog just here : https://www.ssaurel.com/blog

Written by

Entrepreneur / Developer / Blogger / Author. In Bitcoin We Trust: https://www.inbitcoinwetrust.net

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store