How to get android mobile phone model programmatically

Detect android device MANUFACTURER name and model name on button click.

Every android mobile phone contain its model number and manufacturer name but most of peoples doesn’t know their mobile phone model number because there are so much different types of models coming with numbered values. So here is the complete step by step tutorial for How to get android mobile phone model programmatically.

android-project-download-code-button

How to get android mobile phone model programmatically.

Code for MainActivity.java file.

 package com.getandroidmobilephonemodel_android_examples.com;

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 DeviceModel, DeviceName;
 TextView model, device;
 Button getboth;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 model = (TextView)findViewById(R.id.textView1);
 
 device = (TextView)findViewById(R.id.textView2);
 
 getboth = (Button)findViewById(R.id.button1);
 
 getboth.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 
 DeviceModel= android.os.Build.MODEL;
 DeviceName= android.os.Build.MANUFACTURER;
 
 model.setText(DeviceModel);
 device.setText(DeviceName);
 
 }
 });
 
 }
}

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.getandroidmobilephonemodel_android_examples.com.MainActivity" >

 <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="165dp"
 android:text="Device Model"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Device Name"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView2"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="38dp"
 android:text="Click here to get android mobile phone model programmatically" />

</RelativeLayout>

Screenshot :

How to get android mobile phone model programmatically

Click here to download How to get android mobile phone model programmatically project.

Leave a Reply

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