HERE Android SDK Developer's Guide

LiveSight

LiveSight enables user experiences that use the real world as an interface. With LiveSight, developers can overlay geospatial content on the real world, which is displayed using the device's camera. Additionally, an immersive experience is created by using the device's sensors to track movement in space and update the view accordingly.

The key concepts covered in this section include adding LiveSight to an Android application, transitioning from Map Mode to LiveSight Mode, and customizing the LiveSight experience. The classes covered include CompositeFragment and ARController.

Note: LiveSight requires the following sensors enabled:
  • GPS
  • Compass
  • Accelerometer
  • Gyroscope
LiveSight does not function properly, or does not function at all, if these sensors are not working or incorrectly calibrated.

CompositeFragment

The Fragment subclass related to LiveSight functionality is the CompositeFragment. It is called "composite" because it exposes both Map and LiveSight functionality in one Android UI component, with an easy way to switch between the two; therefore, in addition to methods related to LiveSight functionality, the CompositeFragment also includes all of the methods found in the MapFragment. The CompositeFragment is useful in the situation where an application wants to include both map and LiveSight functionality.

The remainder of this section uses the CompositeFragment in code samples and discussions.

Note: The CompositeFragment.getScreenCapture(OnScreenCaptureListener) method has the same functionality as MapFragment.getScreenCapture(OnScreenCaptureListener). It does not support taking screen snapshots of the LiveSight Camera View or AR Objects on a map.

Adding and Initializing the CompositeFragment

The first step to integrate LiveSight functionality into an application is to insert a CompositeFragment into the view layout. This is accomplished by adding com.here.android.mpa.ar.CompositeFragment to the Android XML layout file as follows:

<!-- Example fragment. This can be integrated and annotated
like any other android Fragment or View widget -->
<fragment
  class="com.here.android.mpa.ar.CompositeFragment"
  android:id="@+id/compositefragment"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"/>
Note: When using the CompositeFragment, you do not have to also use the MapFragment. The CompositeFragment is a superset of the MapFragment.

After adding the CompositeFragment to the layout, the fragment must be initialized by calling the CompositeFragment.init(OnEngineInitListener) method. During this asynchronous initialization, the MapEngine is initialized to create an instance of Map that is associated with the CompositeFragment. The ARController is also be created. For more information about ARController, see Customizing LiveSight.

The following code example illustrates the basic initialization flow when an Activity is created. The init(OnEngineInitListener) method uses the OnEngineInitListener parameter to signal the caller when the asynchronous initialization is completed.


@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  // Search for the Composite Fragment
  final CompositeFragment compositeFragment = (CompositeFragment)
     getFragmentManager().findFragmentById(R.id.compositefragment);
  // initialize the Composite Fragment and
  // retrieve the map that is associated to the fragment
  compositeFragment.init(new OnEngineInitListener() {
    @Override
    public void onEngineInitializationCompleted(
        OnEngineInitListener.Error error) {
      if (error == OnEngineInitListener.Error.NONE) {
        // now the map is ready to be used
        map = compositeFragment.getMap();
        // the arController is also ready to be used now
        arController = compositeFragment.getARController();
      } else {
        System.out.println(
          "ERROR: Cannot initialize CompositeFragment");
      }
    }
  });
}
Note: com.here.android.mpa.ar.CompositeFragment has Fragment.setRetainInstance(boolean) set to true; therefore, onCreate(Bundle) should not be called again when Activity is re-created (for example, after an orientation change).

You cannot use this account to purchase a commercial plan on Developer Portal, as it is already associated to plans with different payment methods.

To purchase a commercial plan on Developer Portal, please register for or sign in with a different HERE Account.

Something took longer than expected.

The project should be available soon under your projects page.

Sorry, our services are not available in this region.

Something seems to have gone wrong. Please try again later.

We've detected that your account is set to Australian Dollars (AUD).
Unfortunately, we do not offer checkouts in AUD anymore.
You can continue using your current plan as normal, but to subscribe to one of our new plans,
please register for a new HERE account or contact us for billing questions on selfservesupport@here.com.