我在看Android 4.2年推出的新API.

public boolean isUserAGoat()

用于确定进行此呼叫的用户是否受传送的影响.

返回进行此调用的用户是否为山羊.

该如何以及何时使用?

推荐答案

Android R更新:

在Android R中,此方法总是返回false.谷歌表示,这样做是"为了保护山羊的隐私":

/**
 * 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>
 *
 * <p>As of {@link android.os.Build.VERSION_CODES#R}, this method always returns
 * {@code false} in order to protect goat privacy.</p>
 *
 * @return Returns whether the user making this call is a goat.
 */
public boolean isUserAGoat() {
    if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R) {
        return false;
    }
    return mContext.getPackageManager()
            .isPackageAvailable("com.coffeestainstudios.goatsimulator");
}

先前的答案:

100开始,该方法用于返回false,直到它在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;
}

看起来这个方法对我们这些开发者来说没有实际的用处.之前有人说可能是100.

在API 21中,该实现被更改为判断是否安装了带有软件包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");
}

这是sourcechange.

Java相关问答推荐

验证使用GCP生成的非对称密钥时签名不起作用

将状态栏和导航栏设置为白色,带有深色文本

如何从片段请求数据到活动?在主要活动中单击按钮请求数据?

为什么接口中的主函数而不是类中的主函数在Java 17中编译和运行没有问题?

H2弹簧靴试验跌落台

ApachePOI:不带换行的新行

如何以干净的方式访问深度嵌套的对象S属性?

条件加载@ManyToMany JPA

获取字符串中带空格的数字和Java中的字符

GetChildren().emoveAll()不会删除 node

MimeMessage emlMessage=new MimeMessage(Session,emlInputStream);抛出InvocationTargetException

如何在JavaFX中处理多个按钮

为什么我的回收视图会显示重复的列表?

Spring安全令牌刷新和JWT签名与本地计算的签名不匹配

如何在JavaFX循环中完美地制作一个AudioClip/MediaPlayer?

Android Java:已设置但未读取SharedPreferences

Java.lang.invke.LambdaConversionException:实例方法InvokeVirtual的参数数量不正确

如何在列表(链表)中插入一个新 node (作为prelast)

FETCH类型设置为LAZY,但它仍会发送第二个请求

如何在ImageIO或十二只猴子中旋转TIFF CMYK图像?