|
| 1 | +##安卓中"UserManger.isUserAGoat()"的合适案例? |
| 2 | + |
| 3 | +###问题描述: |
| 4 | +我正在看在安卓4.2里介绍的新API。当看到"UserManger"类时,我遇到了如下的"method": |
| 5 | +public boolean isUserAGoat() |
| 6 | +Used to determine whether the user making this call is subject to teleportations. |
| 7 | + |
| 8 | +Returns whether the user making this call is a goat. |
| 9 | +这个应该怎样使用和什么时候使用? |
| 10 | + |
| 11 | +###回答: |
| 12 | +根据他们的资料,在API21前,这个"method"用来返回"false" |
| 13 | +/** |
| 14 | + * Used to determine whether the user making this call is subject to |
| 15 | + * teleportations. |
| 16 | + * @return whether the user making this call is a goat |
| 17 | + */ |
| 18 | +public boolean isUserAGoat() { |
| 19 | + return false; |
| 20 | +} |
| 21 | +看起来这个"method"对我们开发者没有真正的用途。一些人之前认为它可能是个复活节彩蛋。 |
| 22 | +再次编辑: |
| 23 | +在API21它改为判断是否存在有包"com.coffeestainstudios.goatsimulator"的已安装app。 |
| 24 | +/** |
| 25 | + * Used to determine whether the user making this call is subject to |
| 26 | + * teleportations. |
| 27 | + * |
| 28 | + * <p>As of {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this method can |
| 29 | + * now automatically identify goats using advanced goat recognition technology.</p> |
| 30 | + * |
| 31 | + * @return Returns true if the user making this call is a goat. |
| 32 | + */ |
| 33 | +public boolean isUserAGoat() { |
| 34 | + return mContext.getPackageManager() |
| 35 | + .isPackageAvailable("com.coffeestainstudios.goatsimulator"); |
| 36 | +} |
| 37 | + |
| 38 | +[stackoverflow链接:Proper use cases for Android UserManager.isUserAGoat()](http://stackoverflow.com/questions/13375357/proper-use-cases-for-android-usermanager-isuseragoat) |
0 commit comments