See: Description
| Package | Description |
|---|---|
| com.layar.sdk | |
| com.layar.sdk.data |
The Layar SDK offers a an Android Library project that implements the core functionality of Layar. Using the Layar SDK, it is possible to start our camera view in scan mode and allow your users to scan images (pages, posters, etc.) from your layers and campaigns. It also allows you to open specific layers (primarily used for geo layers). It provides simple methods for integration in your own app.
The Layar SDK supports Android 2.3 and above. It was developed and tested using the Android Developer Tools (ADT) v22 and uses Android 4.3 (API level 18) as the targetSdkVersion. In the documentation, we assume the use of Eclipse as the IDE, but it should be easy to use on other IDE's or the command line (using Ant) as well. Applications build with the SDK have a couple of hardware/software requirements that will be automatically applied to your application:
Required hardware:
camera (back-facing)
Required permissions:
CAMERA
INTERNET
ACCESS_FINE_LOCATION
ACCESS_COURSE_LOCATION
ACCESS_COURSE_UPDATES
ACCESS_NETWORK_STATE
ACCESS_WIFI_STATE
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE
The Layar SDK is distributed as an Android Library project, including project files for Eclipse. After unzipping the SDK distribution package, you need to take the following steps to get started:
Import the Layar SDK library project into Eclipse
In order to use the Layar SDK, you need to import it to your workspace. This can be achieved using "File > New... -> Project...", then choosing "Android Project from Existing Code". On the dialog that shows up, select the folder where you extracted the SDK to and give the project a name (e.g. "layar_sdk").
Add the Layar SDK library project to your own application
After importing the library project, you can reference the library in your project. To do so, right click your applications project, select "Properties", and go to the "Android" tab. In the "Libraries" section, click "Add..." to add the "layar_sdk" library project.
NOTE: The Layar SDK comes with some library .jar files in its libs folder. This may cause conflicts if your application is using other versions of the same libraries (e.g. android-support-v4.jar). If that occurs, you should remove the conflicting .jar file from your project, and (if needed) replace the .jar file in the Layar SDK with the newer version.
NOTE2: If you set up your project using the command-line tools, please add the android-support-v4.jar file to your project manually.
Enabled manifest merging
The Layar SDK declares a couple of Activities and permissions in its own AndroidManifest.xml. These declarations must be merged into your applications AndroidManifest.xml. While it is possible to manually copy the contents into your AndroidManifest.xml, but it is easier to enable manifest merging in your project by adding the following to your applications's project.properties file:
manifestmerger.enabled=true
NOTE: In order for manifest merging to be possible, the targetSdkVersion and minSdkVersion of your application and the Layar SDK should be the same.
NOTE2: Eclipse will not pick up the changes in the project.properties automatically. If you see errors in the logs about missing Activities, please try to restart Eclipse. This should resolve the issue.
To use the Layar SDK, all you need to do is interact with the LayarSDK class. This contains two simple static methods for initialization and starting the Activity.
Initialization
LayarSDK.initialize(Context context, String oauthKey, String oauthSecret);
Before using the Layar SDK, you need to initialize it by providing your application Context and your OAuth credentials. These credentials are used to authenticate your application and to filter the visual search results to include only campaigns from publisher account. This method only needs to be called once in your applications lifetime.
Starting Activity
LayarSDK.startLayarActivity(Context context);
LayarSDK.startLayarActivity(Context context, String layerName);
After initialization, you can simply start the LayarSDKActivity. This will launch the Layar camera view. When no layerName is specified, the Layar activity will launch in scan mode which allows your user to scan and interact with your campaigns. When a layerName is specified, this specific layer is loaded.
You can also customize some things in the flow of the LayarSDKActivity by providing an LayarSDKClient. This client will receive event based callbacks that can be used to control and customize the flow.
LayarSDK.startLayarActivity(Context context, LayarSDKClient sdkClient);
LayarSDK.startLayarActivity(Context context, LayarSDKClient sdkClient, String layerName);
Enabling MapView support
The Layar SDK supports a Google Maps view for the Geo layers. It uses the Google Maps v2 library included in Google Play Services. In order to enable this, you need to add the Google Play Services library project to your app and add your Google Maps API key to your AndroidManifest.xml as described in the Google documentation. The Layar SDK will automatically detect this and enable the "Switch to Map View" menu option.
https://developers.google.com/maps/documentation/android/start
http://developer.android.com/google/play-services/setup.html
Integrating the Layar SDK Fragment
As an alternative to using the LayarSDKActivity, it is also possible to integrate the LayarSDKFragment in your own Activity. This allows you to build a UI on top of the Layar AR view.
NOTE: You are not allowed to alter the size and visibility of the "Powered by Layar" logo as stated in the terms and conditions. When making bigger changes to the appearance of the view, please consult with Layar to verify whether this is acceptable.