I have a requirement where I have to capture IMEI number of the tablet. I went through certain links " How to get the device's IMEI/ESN programmatically in android? " but, the app got crashed with following error. Please suggest me the best possible way to get IMEI no.
MainActivity.Java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textDeviceID = (TextView)findViewById(R.id.deviceid);
String identifier = null;
//retrieve a reference to an instance of TelephonyManager
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null)
identifier = telephonyManager.getDeviceId();
if (identifier == null || identifier .length() == 0)
identifier = Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
}
}}
Activity_Main.XML
<Linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<textview android:id="@+id/deviceid" android:layout_height="wrap_content" android:layout_width="fill_parent">
</textview>
</Linearlayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shilpi.androidtelephonymanager" >
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Error:
Caused by: java.lang.ClassNotFoundException:
Didn't find class "android.view.Linearlayout" on path:
DexPathList[[zip file "/data/app/com.example.shilpi.androidtelephonymanager-2.apk"],
nativeLibraryDirectories=[/data/app-lib/com.example.shilpi.androidtelephonymanager-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)