There's no such API that I know of.
The trick that I have been using, and you are welcome to use as well is to
determine whether a device is a tester device by its ANDROID_ID, and fork different
behaviors accordingly. Something like this:
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;
}
Where ALL_TESTER_DEVICES is a String array containing all testers ANDROID_IDs:
static final String[] ALL_TESTER_DEVICES = {
"46ba345347f7909d",
"46b345j327f7909d" ... };
Once we have this working we can create tester specific logics inside our code:
if (isTesterDevice()) {
perform tester logic
}
We can also pass a isTester field to the backend server as part of the handshake
procedure, allowing it to perform its own set of tester handling.
This works just fine for small teams of testers. When QA teams grows larger, or
when you cannot ingerrogate some of the tester devices for their ID, we find it
useful to allow our testers to flag their identity by adding a special file to
the SDCARD. In that case isTesterDevice() will change to:
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;
}
Hope it helps.