最近,我在android开发人员官方网站上阅读了有关"Create and monitor geofences"部分的信息,发现无法使用此部分代码:
String errorMessage = GeofenceErrorMessages.getErrorString(this,
geofencingEvent.getErrorCode());
实际上,我的android studio不接受 GeofenceErrorMessages 类,并且我无法使用ALT + ENTER快捷方式导入,因为android studio根本无法识别此类。
我设法用这段代码解决了这个问题,但是我真的很想知道GeofenceErrorMessages类发生了什么:
String errorMessage = GeofenceStatusCodes.getStatusCodeString(geofencingEvent.getErrorCode());
对于GeofenceStatusCodes,我使用了以下导入:
import com.google.android.gms.location.GeofenceStatusCodes;
题:
我是否需要在项目中导入某些内容,或者不建议使用 GeofenceErrorMessages类?
我正在使用最新更新的Android Studio 3.5.1版本。
最佳答案
我自己回答了这个问题,因为我认为许多开发者初学者有时会因为这个问题而陷入愚蠢的问题。
我刚刚回到本节,意识到自己有多愚蠢。
GeofenceErrorMessages不是由android库提供的预定义类,它实际上是您需要自己创建的类,您可以随意调用它。
我很困惑,因为它是在官方的android开发者网站上展示的。
这是带有GeofenceErrorMessages类的示例代码(如果需要,可以将其称为Stupid类):
import android.content.Context;
import com.google.android.gms.location.GeofenceStatusCodes;
public class GeofenceErrorMessages {
public static String getErrorCode(Context context, int errorCode) {
switch (errorCode) {
case GeofenceStatusCodes.GEOFENCE_NOT_AVAILABLE:
return "geofence_not_available";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_GEOFENCES:
return "geofence_too_many_geofences";
case GeofenceStatusCodes.GEOFENCE_TOO_MANY_PENDING_INTENTS:
return "geofence_too_many_pending_intents";
default:
return "unknown_geofence_error";
}
}
}
您可以在此处看到GeofenceStatusCodes类是android库中的预定义类,我用它来对不同类型的geofence状态进行排序。
关于java - 谁能解释我 “GeofenceErrorMessages”类发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58660913/