Know your android app version || app version

 

Android app version :

Android app version, Versions play a key role in every aspect of the product, here product may be a app, mobile and anything.Version code clearly shows that there is a update in the product they are using.

When the updates are like 1.0.1, 1.02 and so on there might be a few changes regarding designs or app fixes and minor bugs but when the android app version changed from 1.0 to 2.0 then we can notice a quite a bit of change in app key functionalities.Know your android app version in this tutorial.

Every now and then there is a update in the apps so updating  a app is quite common and to let users know which version of app they are using is a minimum feature every app should have.

When you are developing the app for the first time it will be like version code 1 and version name 1.0

versionCode 1
versionName "1.0"

You can find version in build.gradle(Module:app)

 

As the app updates to further level both version code and name have to be updated accordingly i.e., version code will be 2 and version name may be incremented as 1.0.1. 1.0.2…

You cannot update app with same version code where as you have a flexibility regarding version name but its a best practice to update it.But in both the cases they cannot be decremented.

And also when you upload a new version you can request user to update their app with the new updated one if you know the app version they are using these are the uses of android app version codes.

 

Now lets start

activity_main.xml :

 

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context="com.example.android.versiontest.MainActivity">

    <TextView
        android:id="@+id/currentversiontxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="60dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</RelativeLayout>

 

and now

 

import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity {

    TextView  currentversiontxt;

    String currentVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        currentversiontxt = (TextView) findViewById(R.id.currentversiontxt);

        try {
             currentVersion = this.getPackageManager().getPackageInfo("com.example.android.versiontest", 0).versionName;
            currentversiontxt.setText("currentVersion : "+currentVersion);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }
    }

 

AndroidManifest.xml :

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.versiontest">
  
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Output :

This screen depicts the usage of android app version.

 

android app version

 

If you like this tutorial on android app version do like and share us for more interesting content.If you have any query’s in this tutorial do let us know in the comment section below.

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial on Retrofit Library || Retrofit Android Example

  Android Tutorial on Retrofit Library, Fetching data from server is a most common functionality almost in every app, and...

Close