Android中"UserManger.isUserAGoat()"的合适案例

标签 IT工具网 android

问题描述:

我正在看在安卓4.2里介绍的新API。当看到“UserManger”类时,我遇到了如下的“method”: public boolean isUserAGoat() Used to determine whether the user making this call is subject to teleportations.

Returns whether the user making this call is a goat. 这个应该怎样使用和什么时候使用?

回答:

根据他们的资料,在API21前,这个“method”用来返回“false”

/**
 * 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;
}
看起来这个“method”对我们开发者没有真正的用途。一些人之前认为它可能是个复活节彩蛋。
再次编辑: 在API21它改为判断是否存在有包“com.coffeestainstudios.goatsimulator”的已安装app。
/**
 * Used to determine whether the user making this call is subject to
 * teleportations.
 *
 * As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can
 * now automatically identify goats using advanced goat recognition technology.
 *
 * @return Returns true if the user making this call is a goat.
 */
public boolean isUserAGoat() {
    return mContext.getPackageManager()
            .isPackageAvailable(“com.coffeestainstudios.goatsimulator”);
}

stackoverflow链接:Proper use cases for Android UserManager.isUserAGoat()

相关文章:

java如何用一行代码初始化一个ArrayList

客户端与服务器端编程有什么差别

Java += 操作符实质

java - 如何从 OpenGL ES 2.0 中的数组中读取超过 4 个顶点数据?

android - 还有其他地方可以获取 google-services.json 吗?

android - 将我的 android 应用程序的外部数据库免费放置在 Internet 上的何处

java - serialVersionUID 有什么作用?该如何使用?

如何在classpath中设置多个jar包

java - 如何使用android在textview中显示输出?

Android - Espresso 测试 - 关闭并重新打开应用程序?