0

Does anyone know what the method hasClients does in the android sdk?

boolean com.android.ddmlib.IDevice.hasClients()

It doesn't look like its documented.

I am trying to find a way to see if an emulator is being used. Any good way to do this?

for(int i =0; i < devices.length; i++){

    if(!devices[i].hasClients()){

        monkeyDevice = devices[i];

    }

}

When I say is being used, I mean if there is currently an application running on the device or if its receiving commands from anything.

Update

I should of mentioned that I want to test for these conditions outside from my application. I have a seperate class running outside the application that starts the application within an available emulator. I want this monkey class to know if an existing emulator is already being used for testing.

Abs
  • 56,052
  • 101
  • 275
  • 409
  • Probably http://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-the-emulator will be helpful – Ognyan Oct 31 '11 at 15:53

1 Answers1

0

Have a look at this question to figure out if you are running in the emulator:
How can I detect when an Android application is running in the emulator?

On a monkey-related point, you might want to have a look at Activity.isUserAMonkey() method (since API level 8, OS 2.2). The Google DeviceAdminSample code gives a brief explanation:

/**
 * If the "user" is a monkey, post an alert and notify the caller.  This prevents automated
 * test frameworks from stumbling into annoying or dangerous operations.
 */
private static boolean alertIfMonkey(Context context, int stringId) {
    if (ActivityManager.isUserAMonkey()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(stringId);
        builder.setPositiveButton(R.string.monkey_ok, null);
        builder.show();
        return true;
    } else {
        return false;
    }
}
Community
  • 1
  • 1
Dan J
  • 25,433
  • 17
  • 100
  • 173