Tanzil
Tanzil

Reputation: 111

why this code not working for IMEI call over android?

I want to make a code which get IMEI from phone and check with given data (12345678912345). If it match it'll call onSearchRequested();

Here is my code

long imei=telephonyManager.getDeviceId();
if(imei==12345678912345)
         {
            onSearchRequested();
        }
else
{
         finish();
}

here if(imei==12345678912345) is not working on eclipse. I've used

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> permission.

Upvotes: 0

Views: 190

Answers (2)

Raghunandan
Raghunandan

Reputation: 133560

Try the below

 String mImei = null; 
 TelephonyManager mTeleManager = null; 
 mTeleManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); 
 //Here this refers to activity context
 if(mTeleManager!=null){
  mImei = mTeleManager.getDeviceId(); //get the IMEI number
 }

Then

  if(mImei.equals("12345678912345"))
  {
        onSearchRequested();
  }
  else
  {
     finish();
  }

Upvotes: 2

stinepike
stinepike

Reputation: 54672

       TelephonyManager manager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

       String imei=manager.getDeviceId();

       if(imei=="12345678912345")
       {
          onSearchRequested();
       }
        else
       {
          finish();
       }

Upvotes: 0

Related Questions