0

我想制作一个从手机获取 IMEI 并检查给定数据(12345678912345)的代码。如果匹配,它会调用onSearchRequested();

这是我的代码

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

这里if(imei==12345678912345)不适用于日食。我用过

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

2 回答 2

2

试试下面

 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
 }

然后

  if(mImei.equals("12345678912345"))
  {
        onSearchRequested();
  }
  else
  {
     finish();
  }
于 2013-04-18T17:33:25.537 回答
0
       TelephonyManager manager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

       String imei=manager.getDeviceId();

       if(imei=="12345678912345")
       {
          onSearchRequested();
       }
        else
       {
          finish();
       }
于 2013-04-18T17:33:01.313 回答