GeofenceTransitionIntentService에 객체를 전달하는 데 문제가 있습니다. putExtra()를 사용할 때마다 geofenceTransition이 -1이므로 항상 오류가 발생하고 나머지 코드는 건너 뜁니다. putExtra()를 사용하지 않으면 알림이 작동합니다. 이 문제를 해결할 방법이 있습니까?putExtra()를 사용할 때 지오 코딩 이벤트에 오류가 발생했습니다.
이 코드는 추가 정보를 넣을 코드입니다. currentCharacter는 Character이고 serializable을 구현합니다.
private PendingIntent getGeofencePendingIntent() {
if (geofencePendingIntent != null) {
Log.d(TAG, "getGeofencependingintent return");
return geofencePendingIntent;
}
Intent intent = new Intent(this, GeofenceTransitionIntentService.class);
intent.putExtra("char", currentCharacter);
Log.d(TAG, "getGeofencependingintent new");
return PendingIntent.getService(this, 0, intent, PendingIntent.
FLAG_UPDATE_CURRENT);
}
여기 코드가 잘못되어 있습니다. 이 IntentService를 확장하는 클래스에
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = "err";
Log.e(TAG, errorMessage);
return;
}
// Get the transition type.
int geofenceTransition = geofencingEvent.getGeofenceTransition();
// Test that the reported transition was of interest.
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger multiple geofences.
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
// Send notification and log the transition details.
sendNotification(geofenceTransitionDetails);
Log.d(TAG, geofenceTransitionDetails);
} else {
// Log the error.
Log.e(TAG, "error");
}
currentCharacter = intent.getSerializableExtra("char");
}
'currentCharacter'의 유형은 무엇입니까? –
currentCharacter는 Character이며 직렬화 가능을 구현합니다. –
오, 죄송합니다. 보지 못했습니다. –