【发布时间】:2015-12-20 18:04:08
【问题描述】:
当有人进入我的一个地理围栏时,我想在我的地图上显示一个布局并开始播放一些音频。 我一直在关注一些教程,并且知道如何在它们进入时进行推送通知,但这一切都发生在另一个 IntentService 类中。
也许这就是 onResult 的用途?我不确定如何从结果参数中获取地理围栏信息
LocationServices.GeofencingApi.addGeofences(
gApiClient,
getGeofencingRequest(),
getGeofencePendingIntent()
).setResultCallback(this);
@Override
public void onResult(Result result) {
}
这是我的 intentService 类
public class GeofenceTransitionsIntentService extends IntentService {
private final String TAG = "Geofence_transitions";
public GeofenceTransitionsIntentService() {
super("geo-service");
}
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
String errorMessage = geofencingEvent.getErrorCode()+"";
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_DWELL ||
geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {
// Get the geofences that were triggered. A single event can trigger
// multiple geofences.
ArrayList<Geofence> triggeringGeofences = (ArrayList<Geofence>) geofencingEvent.getTriggeringGeofences();
// Get the transition details as a String.
String geofenceTransitionDetails = getGeofenceTransitionDetails(
this,
geofenceTransition,
triggeringGeofences
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_media_play)
.setContentTitle("Geofence!")
.setContentText(geofenceTransitionDetails);
mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(geofenceTransitionDetails).setBigContentTitle("Big title")
.setSummaryText(geofenceTransitionDetails));
// Send notification and log the transition details.
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
} else {
// Log the error.
Log.e(TAG, getString(R.string.geofence_transition_invalid_type,
geofenceTransition));
}
}
人们通常如何获取触发地理围栏的信息并在主线程上执行某些操作?
【问题讨论】:
标签: android google-maps-android-api-2 android-geofence