确定是否正在使用仿真器设备 [英] Determine if emulator device is in use

查看:83
本文介绍了确定是否正在使用仿真器设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道hasClients在android sdk中的作用吗?

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.

我应该提到我想在我的应用程序中外部测试这些条件.我在应用程序外部运行了一个单独的类,该类在可用的模拟器中启动该应用程序.我想让这个猴子类知道现有的模拟器是否已经用于测试.

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.

推荐答案

看看这个问题,弄清楚您是否正在模拟器中运行:
如何检测何时Android应用程序正在模拟器中运行?

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?

关于猴子,您可能想看看 Activity.isUserAMonkey()方法(自API级别8,OS 2.2起). Google DeviceAdminSample代码进行了简要说明:

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;
    }
}

这篇关于确定是否正在使用仿真器设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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