回答

收藏

Android UserManager.isUserAGoat() 的正确用例?

技术问答 技术问答 329 人阅读 | 0 人回复 | 2023-09-11

我正在查看Android 4.新 引入2 API 。在查看UserManager在课程中,我遇到了以下方法:. ]: X& j8 _0 ^" x9 k7 I3 r
public boolean isUserAGoat()用于确定此呼叫的用户是否会被传输。5 z& F% m4 r$ w
返回此调用的用户是山羊吗?% O* l$ S) L( |+ C9 Y" N
该怎么用,该怎么用?' `4 P. b0 U' X$ E7 u+ s+ }
                                                                ! q6 H' ]+ G& c' P
    解决方案:                                                                , q! a% x+ r7 X- @
                                                                Android R 更新:
  U/ m  I) M2 Q6 X8 P0 `在 Android R 中间,这种方法总是返回 false。谷歌表示这样做是为了to protect goat privacy:
* f5 c% }# B8 h" w/** * 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.: v0 u3 {8 g/ q
* * As of {@link android.os.Build.VERSION_CODES#R},this method always returns * {@code false} in order to protect goat privacy.9 s- @+ S$ j4 v
* * @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");}最后一个答案:0 ^# [" g) E, ~. }% s- h8 j
该方法从他们的来源用于返回,false直到它在 API 21 中有变化。! A- Z8 H" q9 v$ y  D
/** * 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;}作为开发人员,这种方法似乎没有真正的用途。之前有人说可能是复活节彩蛋。
% J3 J" K3 j- _5 l, l7 k9 Q1 Z7 x  s在 API 21 中,已改为检查是否安装了包含软件包的应用程序 com.coffeestainstudios.goatsimulator
) l- i7 [5 H) K, u! b. ^0 ^/** * 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.
3 B/ ^$ X* ^0 M5 f* q9 _- F * * @return Returns true if the user making this call is a goat. */public boolean isUserAGoat()      return mContext.getPackageManager()          .isPackageAvailable("com.coffeestainstudios.goatsimulator");}
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则