Demo:
1) MainActivity.java:
2) activity_main.xml:
3) Add this Permission in your manifest.xml:
4) Download this Project Click Here
1) MainActivity.java:
package
com.venky.getimeinumberdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
TelephonyManager
tmanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei =
tmanager.getDeviceId();
tv.setText("Your IMEI Number\n" +
imei);
}
}2) activity_main.xml:
<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:background="#5F04B4"
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=".MainActivity"
>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
android:textColor="#ffffff"
android:textSize="20dp"
android:textStyle="bold"
/>
</RelativeLayout>
3) Add this Permission in your manifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
No comments:
Post a Comment