Android模拟器的设备标识符 [英] Device identifier of Android emulator

查看:757
本文介绍了Android模拟器的设备标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在模拟器中进行测试的应用程序,取决于设备标识符(ANDROID_ID)的

I want to test in the emulator an app that depends of the device identifier (ANDROID_ID).

我目前得到的设备标识符与以下code:

I currently obtain device identifier with the following code:

final String deviceID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);

当我运行这个在它返回,这给了我所有这类问题的模拟器。似乎更高的Andr​​oid版本中,它返回的东西。

When I run this in an emulator it returns null, which gives me all sort of problems. It seems that higher Android versions it returns something.

有没有一种方法可以在Android模拟器设备标识符?难道我获得的设备ID错误?

Is there a way to get a device identifier in the Android emulator? Am I obtaining the device id wrongly?

也许这是可以通过控制台来设置仿真器的设备标识符?

Maybe it's possible to set the device identifier of the emulator through the console?

推荐答案

在模拟器,IMEI和IMSI的值<一href="http://android.git.kernel.org/?p=platform/external/qemu.git;a=blob;f=telephony/android_modem.c;h=0df1186eddd7ec734ace99f8fba59a9ba3edc9af;hb=HEAD">hard$c$cd:

In the emulator, the values of IMEI and IMSI are hardcoded:

2325     { "+CIMI", OPERATOR_HOME_MCCMNC "000000000", NULL },   /* request internation subscriber identification number */
2326     { "+CGSN", "000000000000000", NULL },   /* request model version */

所以,你总是会得到

如果您的还是的想用这些ID号为您的测试,并要保持相同的code的模拟器和真实的设备,必须在模拟器中以某种方式改变它。

If you still want to use these id numbers for your testing and you want to keep the same code for the emulator and the real device, you must change it in the emulator somehow.

至少有两种方法如何做到这一点:

  1. 更​​改值在code和重新编译code仿真器。然而,这可能是太复杂和费时...: - )

  1. Change the values in the code and recompile the code for the emulator. However, this might be too complicated and time consuming... :-)

黑客的模拟器二进制文件(因为它既不COM pressed或加密 - !你可以做到这一点),并修改字符串(在正确的地方),在那里

"Hack" the emulator binary (since it is neither compressed or encrypted - you can do it!) and modify the strings (in the right place) right there.

下面是如何做到这一点:

  • 备份模拟器二进制文件(回滚!以后)。在Windows中,二进制文件可以在名为emulator.exe,位于你的android\工具文件夹中找到。

  • backup the emulator binary (to roll back! later). In Windows, the binary can be found under the name "emulator.exe", located in your android "\tools" folder.

用你喜欢的十六进制编辑器打开二进制

open the binary with your favourite hex editor

搜索 + CGSN 字符串,后跟一个空字节(它应遵循15的IMEI号码数字 - 见下面PRINTSCREEN)

search for the +CGSN string followed by a null byte (it should be followed by 15 digits of the IMEI number - see the printscreen below)

  • 编辑号码(注意不要改变的数字原号码)

  • edit the number (be careful not to change the original number of the digits)

和保存文件!

和可能改变/调整code使用的IMEI为您的ID(如 Falmari 指出),或使用这种伎俩来改变一些其他值。

and maybe change/adjust your code to use the IMEI for your id (as Falmari points out), or use this trick to change some other values.

这篇关于Android模拟器的设备标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆