In this blog we will explain how to get system information for example Device IMEI & Android Secure id.
First you can add READ_PHONE_STATE permission in android manifest file .
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
activity_main.xml.
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center|top">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:gravity="center"
android:textStyle="bold"
android:textColor="#066001"
android:visibility="visible"
android:text="ANDROID BEGINNER POINT TUTORIAL"
android:id="@+id/textView" />
<Button
android:text="Get System Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:id="@+id/button" />
<TextView
android:text="IMEI No."
android:textColor="#991313"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textemei"
android:textSize="18dp"
android:layout_marginTop="30dp"
tools:text="IMEI No." />
<TextView
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#991313"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewemi" />
<TextView
android:text="Android Id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textid"
android:layout_marginTop="30dp"
android:textSize="18dp"
android:textColor="#c345d3"
tools:text="Android Id" />
<TextView
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#c345d3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewid" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center|top">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:gravity="center"
android:textStyle="bold"
android:textColor="#066001"
android:visibility="visible"
android:text="ANDROID BEGINNER POINT TUTORIAL"
android:id="@+id/textView" />
<Button
android:text="Get System Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:id="@+id/button" />
<TextView
android:text="IMEI No."
android:textColor="#991313"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textemei"
android:textSize="18dp"
android:layout_marginTop="30dp"
tools:text="IMEI No." />
<TextView
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#991313"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewemi" />
<TextView
android:text="Android Id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textid"
android:layout_marginTop="30dp"
android:textSize="18dp"
android:textColor="#c345d3"
tools:text="Android Id" />
<TextView
android:text=""
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#c345d3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewid" />
</LinearLayout>
MainActivity.Java.
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ Button btninfo; TextView textIMEI,textid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textIMEI=(TextView)findViewById(R.id.textViewemi); textid=(TextView)findViewById(R.id.textViewid); btninfo=(Button)findViewById(R.id.button); btninfo.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.button: textIMEI.setText(getIMEI()+"."); textid.setText(getAndroidId()+"."); break; } } public String getIMEI() { TelephonyManager telephonyManager = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getDeviceId(); } public String getAndroidId() { return Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID); } }
0 comments