在游戏上线之后可能会遇到这样的问题,有人用模拟器恶意刷金币或者注册啊等问题,这个时候我们就需要把那些用模拟器登录玩家的某些功能屏蔽掉或者直接不让其登录,这个因人而异了。下面就说一下如何鉴别真机和模拟器,网上的方法也有很多,什么压力传感器温度传感器啊光传感器等,然而我这边经过研究之后,只有一个光传感器还算靠谱,鉴别成功率最好了。
下面直接上代码吧,不比比了。
java代码:
/**
* 判断是否存在光传感器来判断是否为模拟器
* 部分真机也不存在温度和压力传感器。其余传感器模拟器也存在。
* @return true 为模拟器
*/
public static int getmmethod(){
boolean isMmethod = true;
try {
Class<?> mclass = Class.forName("android.os.SystemProperties");
Object invoker = mclass.newInstance();
Method mmethod = mclass.getMethod("get", new Class[] { String.class,String.class });
Object result = mmethod.invoke(invoker, new Object[] {"gsm.version.baseband", "0000" });
Log.i("基带版本:", (String) result);
if ((String) result == "0000"){
isMmethod = false;
}
} catch (Exception e) {
}