据我所知,没有这样的 API。
我一直在使用的技巧,也欢迎您使用
通过ANDROID_ID判断一个设备是否为测试设备,并fork不同
相应的行为。像这样的:
static String androidId;
static boolean isTesterDevice;
boolean isTesterDevice() {
if (androidId != null) {
return isTesterDevice; // optimization: run string compares only once
}
androidId = Secure.getString(context.getContentResolver(),Secure.ANDROID_ID);
isTesterDevice = Arrays.asList(ALL_TESTER_DEVICES).contains(androidId);
return isTesterDevice;
}
其中 ALL_TESTER_DEVICES 是一个包含所有测试人员 ANDROID_ID 的字符串数组:
static final String[] ALL_TESTER_DEVICES = {
"46ba345347f7909d",
"46b345j327f7909d" ... };
一旦我们完成这项工作,我们就可以在我们的代码中创建特定于测试器的逻辑:
if (isTesterDevice()) {
perform tester logic
}
我们还可以将 isTester 字段作为握手的一部分传递给后端服务器
过程,允许它执行自己的一组测试程序处理。
这对于小型测试团队非常有效。当 QA 团队变大时,或
当您无法从某些测试设备中获取其 ID 时,我们会找到它
有助于让我们的测试人员通过添加一个特殊文件来标记他们的身份
SD卡。在这种情况下 isTesterDevice() 将更改为:
boolean isTesterDevice() {
if (androidId != null) {
return isTesterDevice; // optimization: run string compares only once
}
// check by device ID
androidId = Secure.getString(context.getContentResolver(),Secure.ANDROID_ID);
isTesterDevice = Arrays.asList(ALL_TESTER_DEVICES).contains(androidId);
if (!isTesterDevice) {
// check by tester file
File sdcard = Environment.getExternalStorageDirectory();
File testerFile = new File(sdcard.getAbsolutePath(), "I_AM_TESTER.txt");
isTesterDevice = testerFile.exists();
}
return isTesterDevice;
}
希望对你有帮助。