Android UserManager.isUserAGoat() 的正确用例?
技术问答
379 人阅读
|
0 人回复
|
2023-09-11
|
我正在查看Android 4.新 引入2 API 。在查看UserManager在课程中,我遇到了以下方法:, G! H( p! s, w! }
public boolean isUserAGoat()用于确定此呼叫的用户是否会被传输。
/ u! ?4 }7 [" V' q4 G+ `3 [返回此调用的用户是山羊吗?
8 H4 b' @7 B; O* @6 c0 z8 z该怎么用,该怎么用?
; G; c; T1 J0 U ~& Z P , X6 M! }+ E9 L1 U7 o
解决方案:
) T, `/ [ j5 Y" G% h9 P/ H; G Android R 更新:: j0 r ^ ~; k; j9 \9 q
在 Android R 中间,这种方法总是返回 false。谷歌表示这样做是为了to protect goat privacy:
* Z" k$ b9 Q) Y' [: `0 h0 e: R/** * 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- P& f7 A9 ] * * As of {@link android.os.Build.VERSION_CODES#R},this method always returns * {@code false} in order to protect goat privacy.2 ]; X% ^5 V7 \$ W0 ^8 g* j
* * @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");}最后一个答案:* c' i7 ]. u3 C X& i
该方法从他们的来源用于返回,false直到它在 API 21 中有变化。0 Y9 o0 M4 n( G9 [, {+ R
/** * 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;}作为开发人员,这种方法似乎没有真正的用途。之前有人说可能是复活节彩蛋。6 `7 i6 ?9 Z) d4 V1 C
在 API 21 中,已改为检查是否安装了包含软件包的应用程序 com.coffeestainstudios.goatsimulator
2 X6 t. M; A9 T% h: k* o# l! ?/** * 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.
: r9 B4 P1 D7 l- g9 k4 }8 r * * @return Returns true if the user making this call is a goat. */public boolean isUserAGoat() return mContext.getPackageManager() .isPackageAvailable("com.coffeestainstudios.goatsimulator");} |
|
|
|
|
|