Get current device language (Detect) in android programmatically

How to detect android mobile phone current default language dynamically using android application.

Detecting current language of android mobile phone is very important feature to create multi language support android applications which can automatically changes app language according to device language. So here is the complete step by step tutorial for Get current device language (Detect) in android programmatically.

android-project-download-code-button

How to Get current device language (Detect) in android programmatically.

Code for MainActivity.java file.

 package com.getcurrentdevicelanguage_android_examples.com;

import java.util.Locale;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

 String Language;
 Button GetLanguageButton;
 TextView DisplayLanguageTextView;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 GetLanguageButton = (Button)findViewById(R.id.button1);
 
 DisplayLanguageTextView = (TextView)findViewById(R.id.textView1);
 
 GetLanguageButton.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 Language = Locale.getDefault().getDisplayLanguage().toString();
 
 DisplayLanguageTextView.setText(Language);
 
 }
 });
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.getcurrentdevicelanguage_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="22dp"
 android:text="Click here to Get current device language in android programmatically" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="168dp"
 android:text="Default Text"
 android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Screenshot:

Get current device language in android programmatically

Click here to download Get current device language (Detect) in android programmatically project.

Leave a Reply

Your email address will not be published. Required fields are marked *