回答

收藏

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

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

我正在查看Android 4.新 引入2 API 。在查看UserManager在课程中,我遇到了以下方法:
- ], p- K+ b3 c0 `. k9 [public boolean isUserAGoat()用于确定此呼叫的用户是否会被传输。* Q- \0 ?1 k+ v' Y: R% e" `: u: h
返回此调用的用户是山羊吗?6 K1 F: W+ C# W, l/ E. ]
该怎么用,该怎么用?
2 g- G4 d" I+ {# d) r% @# j4 E  P& h                                                                0 y$ y5 j* u7 ^# w
    解决方案:                                                                6 t+ Q3 ~* L$ z( Q. L# u3 x- y
                                                                Android R 更新:
$ I3 u. q$ d- r# r: Z在 Android R 中间,这种方法总是返回 false。谷歌表示这样做是为了to protect goat privacy:" S! h9 ~4 v, g* l6 R4 A/ Y
/** * 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.8 V3 P. Y/ U0 d& S( N+ ~* F
* * As of {@link android.os.Build.VERSION_CODES#R},this method always returns * {@code false} in order to protect goat privacy.% b3 ~/ H3 K$ G
* * @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");}最后一个答案:9 w3 \2 _7 b% K$ _: t4 E4 }
该方法从他们的来源用于返回,false直到它在 API 21 中有变化。0 c2 w' V. o7 g- R0 `+ K' p2 `' t
/** * 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;}作为开发人员,这种方法似乎没有真正的用途。之前有人说可能是复活节彩蛋。
8 S& h1 B0 t: F在 API 21 中,已改为检查是否安装了包含软件包的应用程序 com.coffeestainstudios.goatsimulator3 b* N3 g: x. p
/** * 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., h, N* C2 q% F) R) Y! u  z; |$ F
* * @return Returns true if the user making this call is a goat. */public boolean isUserAGoat()      return mContext.getPackageManager()          .isPackageAvailable("com.coffeestainstudios.goatsimulator");}
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则