正确使用的情况下为Android UserManager.isUserAGoat()?情况下、正确、Android、UserManager

2023-09-12 01:23:24 作者:三千青丝为谁愁

我一直在寻找在的Andr​​oid 4.2 推出了新的API。 在注视UserManager一流的我碰到下面的方法:

I was looking at the new APIs introduced in Android 4.2. While looking at the UserManager class I came across the following method:

公共布​​尔isUserAGoat()

public boolean isUserAGoat ()

用于确定在进行此调用用户是否受到teleportations。

Used to determine whether the user making this call is subject to teleportations.

返回在进行此调用用户是否是山羊。

Returns whether the user making this call is a goat.

如何以及何时该使用?

推荐答案

从他们的 source,该方法用于返回,直到它在21 API被改变。

From their source, the method used to return false until it was changed in API 21.

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 * @return whether the user making this call is a goat 
 */
public boolean isUserAGoat() {
    return false;
}

它看起来像方法没有真正使用我们作为开发商。有人做过previously表示,它可能是一个 复活节彩蛋 。

It looks like the method has no real use for us as developers. Someone has previously stated that it might be an Easter egg.

编辑:

在21 API执行改为检查是否有与包的安装的应用程序 com.coffeestainstudios.goatsimulator

In API 21 the implementation was changed to check if there is an installed app with the package com.coffeestainstudios.goatsimulator

/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
 * now automatically identify goats using advanced goat recognition technology.</p>
 *
 * @return Returns true if the user making this call is a goat.
 */
public boolean isUserAGoat() {
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

下面是更新后的 source链接

Here is the updated source link