我希望在进入/退出地理围栏区域时直接将活动带到前台。
我有 5 个地理围栏区域,当我进入地理围栏区域 A(以纬度/经度指定)时,我希望将 ActivityA 带到前台,当我在地理围栏时,活动 B 是 B 等等。(这是一个非消费者应用程序,所以我不介意直接从服务调用活动到前台。)
我已阅读有关 Android 中地理围栏的文档。当他们收到地理围栏区域的不同 ID 时,我如何调用不同的活动?
待定意图:
public class MainActivity extends FragmentActivity {
...
private PendingIntent getTransitionPendingIntent() {
Intent intent = new Intent(this,
ReceiveTransitionsIntentService.class);
return PendingIntent.getService(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
...
}
和处理程序意图:
protected void onHandleIntent(Intent intent) {
if (LocationClient.hasError(intent)) {
int errorCode = LocationClient.getErrorCode(intent);
Log.e("ReceiveTransitionsIntentService",
"Location Services error: " +
Integer.toString(errorCode));
} else {
// Get the type of transition (entry or exit)
int transitionType =
LocationClient.getGeofenceTransition(intent);
// Test that a valid transition was reported
if (
(transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
||
(transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
) {
List <Geofence> triggerList =
getTriggeringGeofences(intent);
String[] triggerIds = new String[geofenceList.size()];
for (int i = 0; i < triggerIds.length; i++) {
// Store the Id of each geofence
triggerIds[i] = triggerList.get(i).getRequestId();
}
}
} else {
Log.e("ReceiveTransitionsIntentService",
"Geofence transition error: " +
Integer.toString()transitionType));
}
}