Android代码判断当前设备是否为模拟器

判断当前设备是否为模拟器:

package com.example.checkisemulator;  
  
import android.os.Build;  
import android.os.Bundle;  
import android.app.Activity;  
import android.content.Context;  
import android.telephony.TelephonyManager;  
import android.view.Menu;  
  
public class MainActivity extends Activity {  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        boolean b = isEmulator(getApplicationContext());  
        if (b) {  
            finish();  
        }  
    }  
  
    /** 
     * 判断当前设备是否是模拟器。如果返回TRUE,则当前是模拟器,不是返回FALSE 
     *  
     * @param context 
     * @return 
     */  
    public static boolean isEmulator(Context context) {  
        try {  
            TelephonyManager tm = (TelephonyManager) context  
                    .getSystemService(Context.TELEPHONY_SERVICE);  
            String imei = tm.getDeviceId();  
            if (imei != null && imei.equals("000000000000000")) {  
                return true;  
            }  
            return (Build.MODEL.equals("sdk"))  
                    || (Build.MODEL.equals("google_sdk"));  
        } catch (Exception e) {  
  
        }  
        return false;  
    }  
}  


--------------------------------------------------------------------------------

参考文章出处:

http://blog.csdn.net/u010358168/article/details/42964735

http://blog.csdn.net/androidstarjack/article/details/53400463


你可能感兴趣的:(Android代码判断当前设备是否为模拟器)