Device Year Class Library Using Android Application

This article demonstrates how to add device year class library using the android studio and XML code.

Android library that implements a simple algorithm that maps a device's RAM, CPU cores, and clock speed to the year where that combination of specs was considered high end. This allows a developer to easily modify application behavior based on the capabilities of the phone's hardware. 
RAM Condition Year Class
7681 core2009
1GB2+ core2010
more2.2GHz2016 & 2017
Let's start,
Step 1
Create a new project in Android Studio from File >> Project and fill all the necessary details.
Next, go to Gradle Scripts >> build.gradle (Module: app).Select build.gradle, The app gradle compile the code and build types will appear. Just replace that the following code.To make a Device year class in your layout XML and add the device year library in your project or you can also Gradle
Download the latest JARs or grab via Gradle,
Compile Code
  1. compile 'com.facebook.device.yearclass:yearclass:2.0.0'  
or Maven
  1. <dependency>  
  2.   <groupId>com.facebook.device.yearclass</groupId>  
  3.   <artifactId>yearclass</artifactId>  
  4.   <version>2.0.0</version>  
  5. </dependency>  
Step 2
Next, go to app >> res >> layout >> activity_main.xml. 
Select activity page. The XML code will appear, Just the following code. Create the layout of the TextView and Button.  
Design View 
Step 3
Next, go to app >> src >> >>main >> java >> The jave code will appear. Just replace that with the following jave code 
Calculate Device Year Class  
Calculating  the current device's year class is simple
  1. int year = YearClass.get(getApplicationContext());  
Then, later on, you can use the year class to make decisions in your app, or send it along with your analytics.
  1. package com.example.ravi.myapplication;  
  3. import;  
  4. import android.os.Bundle;  
  5. import android.view.View;  
  6. import android.widget.Button;  
  7. import android.widget.TextView;  
  9. import com.facebook.device.yearclass.YearClass;  
  11. public class MainActivity extends AppCompatActivity {  
  13.     Button button;  
  14.     TextView textView;  
  15.     @Override  
  16.     protected void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.activity_main);  
  20.         button = (Button) findViewById(;  
  21.         textView = (TextView) findViewById(;  
  23.         button.setOnClickListener(new View.OnClickListener() {  
  24.             @Override  
  25.             public void onClick(View view) {  
  27.                 int year = YearClass.get(getApplicationContext());  
  28.                 String text;  
  30.                 //textView.setText("Current Device year now " + year);  
  32.                 if (year >= 2013) {  
  33.                     text= "Do advanced animation";   
  34.                 } else if (year > 2010) {  
  35.                     text = "Do simple animation";  
  36.                 } else {  
  37.                     text = "Phone too slow, don't do any animations";  
  38.                 }  
  39.                 textView.setText("Device year=" + year +"\nDevice capacity="+ text);  
  41.             }  
  42.         });  
  44.     }  
  45. }  
Next, go to Android Studio and Deploy the application, Select Emulator or your Android mobile with USB debugging enabled. Give it a few sec to make installations and set permission
Run the application in your desired emulator (Shift + F10)

Finally, we have successfully created Device Year Class application. Later we will discuss more Android Applications.

Up Next
    Ebook Download
    View all
    View all