Integrate Android SDK with Android Studio
As of v.8.4 the Layar SDK can be integrated using Android Studio.Bellow you can find instructions on how to configure your app in order to launched the Layar scanner
Hardware and software Requirements
The Layar SDK requires:
- a minimum installed Android version 2.3
- Android device that has a back-facing camera (android version 2.3.x and above)
Configure the project according to the Layar SDK documentation
1. Add the Layar SDK repository in build.gradle
In order to use the Layar SDK class you need to import the library which is available on Maven. Go to App-Gradle Scripts - build.grade(Module:DemoApp) and add the repository
allprojects { repositories { jcenter() maven { url "http://link to the repository" } } }
The file should now look like this:
Another way to add dependency is by adding .arr file
Unzip the AAR file from the SDK distribution package. In Android studio, use "File > New > New Module...", select "Import .JAR/.AAR Package" and select the layar_sdk.aar file. Next add the following dependency in your app's build.gradle file:
dependencies { compile project(':layar_sdk') }
2.Add the sdk dependencies in build.grade
Go to App-Gradle Scripts - build.grade(Module:App) and under the dependencies section add the following:
compile 'com.layar:sdk:8.4.1'
Now the file should look like this:
NOTE: If you do not have the link to the maven repository please get in touch with us through this form to receive all necessary information
Implement the code which launches the Augmented Reality View
In order to use the Layar SDK in an application, all you need to do is interact with the LayarVisionSDK class. This contains two simple static methods for initialization and starting the Activity.
- Initialization
LayarVisionSDK.initialize(Context context, String oauthKey, String oauthSecret);
Before using the Layar Vision 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 your layar account. This method only needs to be called once in your applications lifetime.
- Starting Activity
LayarVisionSDK.startLayarVisionActivity(Context context);
After initialization, you can simply start the LayarVisionActivity. This will launch the Layar Camera view in scan mode, which allows your user to scan and interact with your campaigns.
In LaunchLayar.java file, we will create a function named "launch" :
public void launch(View view) { String oauthKey = "your oauthKey"; String oauthSecret = "your oauthSecret"; LayarSDK.initialize(this, oauthKey, oauthSecret); LayarSDK.startLayarActivity(this); }
Please use the correct "key" and "secret" that you have obtained from Layar when you requested the SDK.