Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Get the Build Version Number of an Android Application using Jetpack Compose?
Next article icon

How to Get the Build Version Number of an Android Application?

Last Updated : 24 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Version Name and Version Code in an Android application tell us about the current app version installed on the user's mobile device. This information is generally used when we prompt users to update to the new version of the older version of the application. In this article, we will look at How to get the Build Version Number of an Android application. 

Note: This Android article covered in both Java and Kotlin languages. 

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Step 2: Working with the activity_main.xml file

Navigate to app > res > layout > activity_main.xml and add the below code to it. Comments are added in the code to get to know in detail. 

XML
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/idRLContainer"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     tools:context=".MainActivity">      <!--on below line we are creating         a text for our app-->     <TextView         android:id="@+id/idTVHeading"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_above="@id/idTVVersionNumber"         android:layout_centerInParent="true"         android:layout_margin="20dp"         android:gravity="center"         android:padding="10dp"         android:text="Build Version Number of Android App"         android:textAlignment="center"         android:textColor="@color/black"         android:textSize="20sp"         android:textStyle="bold" />      <TextView         android:id="@+id/idTVVersionNumber"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:layout_margin="20dp"         android:gravity="center"         android:text="Version"         android:padding="10dp"         android:textAlignment="center"         android:textColor="@color/black"         android:textSize="20sp"         android:textStyle="bold" />  </RelativeLayout> 

Step 3: Working with the MainActivity file 

Navigate to app > java > your app's package name > MainActivity file and add the code below. Comments are added in the code to get to know in detail. 

Kotlin
package com.gtappdevelopers.kotlingfgproject  import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity  class MainActivity : AppCompatActivity() {      // on below line creating a variable.     lateinit var versionTV: TextView      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          // on below line we are initializing our variables.         versionTV = findViewById(R.id.idTVVersionNumber)                  // on below line we are creating a variable and storing         // our version name and version code.         val version =             "Version Name : " + BuildConfig.VERSION_NAME + "\n" + "Version Code : " + BuildConfig.VERSION_CODE.toString()          // on below line we are setting version          // name and code to our text view.         versionTV.text = version       } } 
Java
package com.gtappdevelopers.kotlingfgproject;  import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity;  public class MainActivity extends AppCompatActivity {      // on below line we are creating variables.     private TextView versionTV;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          // on below line we are initializing our variables.         versionTV = findViewById(R.id.idTVVersionNumber);                  // on below line we are creating a variable and storing          // our version name and version code.         String version =                 "Version Name : " + BuildConfig.VERSION_NAME + "\n" + "Version Code : " + BuildConfig.VERSION_CODE.toString()          // on below line we are setting version         // name and code to our text view.         versionTV.setText(version);      } } 

Now run your application to see the output of it. 

Output:

Output
 

Next Article
How to Get the Build Version Number of an Android Application using Jetpack Compose?

C

chaitanyamunje
Improve
Article Tags :
  • Java
  • Kotlin
  • Android
Practice Tags :
  • Java

Similar Reads

  • How to Get the Build Version Number of an Android Application using Jetpack Compose?
    Version Name and Version Code in an Android application tell us about the current app version installed on the user's mobile device. This information is generally used when we prompt users to update to the new version of the older version of the application. In this article, we will look at How to g
    3 min read
  • How to Build Android Applications with Gradle?
    There are several contemporary build automation technologies available nowadays that may be utilized to create a quicker build when creating a project. Gradle is one of these modern-day automation technologies. Gradle is now used by Android to automate and control the build process while also defini
    8 min read
  • How to Build and Release Flutter Application in Android Device?
    Flutter is Google’s Mobile SDK to build native iOS and Android, Desktop (Windows, Linux, macOS), Web apps from a single codebase. When building applications with Flutter everything towards Widgets – the blocks with which the flutter apps are built. They are structural elements that ship with a bunch
    2 min read
  • How to Change an Android App's Name?
    Whenever you make a project in Android studios you give a project name, your app's name is derived from that. Consider after working on your project in mid-way or in the end you want to change your app's name how do you do that? Well, this article is concerned with that, let us see how to do it. Ste
    1 min read
  • How to Add Manifest Permission to an Android Application?
    An AndroidManifest.xml file must be present in the root directory of every app project's source set. The manifest file provides crucial information about your app to Google Play, the Android operating system, and the Android build tools. Adding permissions to the file is equally important. In this a
    2 min read
  • How to Get the Unique ID of an Android Device?
    There are different types of unique IDs present for a single android device. We can get IDs such as a device ID, IMEI which is also a unique ID, and many others. In this article, we will take a look at How to Get the Unique ID of an Android Device. Note: This Android article covered in both Java and
    2 min read
  • Build an Android App to Check a Number is Automorphic or Not
    What is an Automorphic number? A number is said to be Automorphic if its square ends in the same digits as the number itself.  Examples: Input : N = 76 Output : Automorphic Explanation: As 76*76 = 5776 Input : N = 25 Output : Automorphic As 25*25 = 625 Input : N = 7 Output : Not Automorphic As 7*7 =
    3 min read
  • How to Get the MAC of an Android Device using NetworkInterface Class?
    The MAC (Media Access Control) address in Android is a unique identifier assigned to the Wi-Fi module of the device. It is used to identify devices on a network and helps in network communication and security. The general method for getting the MAC address of the android device is using the Wifi Man
    3 min read
  • How to Change the Default Icon of Android App?
    In order to get the app published in stores like Google Play Store, Amazon App Store, etc, or if you just want to personalize the app, the default icon can be changed. We can change the icon of the Android App by using Android Studio itself and by following the below steps: Step 1: Create Android St
    2 min read
  • Android Package Name vs Application ID
    As an Android Developer, you should know that the Package Name that you choose for your app is very important. We are referring to the Package Name of the application which we declare in the Manifest.xml rather than the Java package name (although they will be identical). But there is a difference b
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences