Website Visitor

Wednesday, 16 October 2013

Tutorial - Integrate Android SDK

In this step by step tutorial, we demonstrate how to integrate the Android Layar SDK into an Android app. The scope of the tutorial is summarized below:

Hardware and software Requirements

The Layar SDK requires:
  • a minimum installed Android version 2.2
  • Android development environment set-up (such as Eclipse)
  • Android device that has a back-facing camera (android version 2.2.x and above)
For this tutorial we used:
  • Android Developer Tools (ADT) v21.1 (Get the Android SDK )
  • Mac OS X version 10.8.2 
  • A test device, Samsung Galaxy SII with Android v4.1.2

Create a simple Android application

1.Launch ADT and select File->New-> New Android Application Project and click "Next".

2.In the new window, fill in the information regarding your app. 
Please make sure that the package name is the same as the one you set when you requested the SDK Key and Secret. 
We will call our demo project "SDKDemo". Minimum Required SDK should be set to API 8 and Target SDK should be API 17.

3.Configure project as shown below and click on "Next"

4. Configure the attributes of the icon set. We chose to leave default option as is. Once you finish with configuration click on "Next".

 5. in the new window check the box Create Activity and select New Blank activity. Click on "Next"

6. Fill in the activity name. We will name our activity LaunchLayar. When done click "Finish"

7. Now, you have created a new Android app called "SDKDemo". The project structure will look like this:

8. Browse through the folder navigation SDKDemo->res->layout and open file activity_layar.xml. Once the file opens, select tab Graphical Layout.

9. Delete the Hello world reference. Drag and drop a button to the Graphical Layout from Form Widgets tab.

10.  Browse through the folder navigation SDKDemo->res->values and open strings.xml and add the following line:
   <string name="Launch_Layar">Launch Layar</string>
The file should now look like this:

11. Now go back to file activity_layar.xml and replace the references to button to Launch_Layar. We will also add onClick="launch". We will later create a launch method that to launch Layar AR. The file should now look like this:

 At this moment, we have created an Android app with a button called Launch Layar which is not doing anything yet. You can run it on an Android device to check it out.

Next, we will configure the project to include the Layar SDK.

Configure the project according to the Layar SDK documentation

1. Download and unzip the Layar SDK file (in this tutorial, we used SDK v7.2.2). 

Firstly, please check the readme.txt file to make sure that you have all the files needed. Unzip the file and place the extracted folder in a place where you can easily track it.

 2. Import the Layar Vision SDK library project into Eclipse

As the eclipse project files are included in the SDK, you just need to import the project to your workspace. This can be achieved using File > Import->Existing Projects into Workspace

Click "Next" and select the Layar Vision SDK project directory and select project "layar_vision_sdk", click "Finish" 

3.Add the Layar Vision 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_vision_sdk" library project.

 NOTE: The Layar Vision 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 Vision SDK with the newer version. 

4.Enabled manifest merging

The Layar Vision 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 Vision 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.

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"; 

LayarVisionSDK.initialize(this, oauthKey, oauthSecret);

LayarVisionSDK.startLayarVisionActivity(this, menuHolder); } 
Please use the correct "key" and "secret" that you have obtained from Layar when you requested the SDK.
Our LaunchLayar.java file now looks like this:

Build and run

Before you can run your application on a device, you must enable USB debugging on your device.
 - On most devices running Android 3.2 or older, you can find the option under Settings > Applications > Development.
- On Android 4.0 and newer, it's in Settings > Developer options.
Once set up and your device is connected via USB, install your application on the device by selecting Run > Run  from the Eclipse menu bar.

Select the device you want to use and press "Ok". That's it!

Localize the app

Since version 7.2.2 the LayarSDK supports localization. You are provided with localizations for English, Dutch, German, French, Spanish and Japanese.
If you are interested in adding another language currently not supported you need to follow these steps:
1.On your project right click on folder res and add a new folder

2. Name the folder values- the initials of the language you would like to add in our case the name is values-it (for italian)

3. Copy on this folder the strings-player.xml file that you can find on Layar SDK file under res->values folder. Open this file and translate the Strings. For your SDK app you can limit translation to Vision AR View strings.

24 comments:

  1. When I initially commented, I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the same comment. Is there any way you can remove people from that service? Thanks.
    Amazon Web Services Training in OMR , Chennai | Best AWS Training in OMR,Chennai
    Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai

    ReplyDelete
  2. I'm here representing the visitors and readers of your own website say many thanks for many remarkable
    python training in OMR
    python training in Bangalore
    python training in Bangalore

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Resources like the one you mentioned here will be very useful to me ! I will post a link to this page on my blog. I am sure my visitors will find that very useful
    Blueprism training in Pune

    Blueprism online training

    Blue Prism Training in Pune

    ReplyDelete
  5. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    ReplyDelete



  6. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.

    angularjs Training in online

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in btm

    ReplyDelete
  7. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    java training in chennai | java training in bangalore


    java training in tambaram | java training in velachery

    ReplyDelete
  8. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us
    Python training in marathahalli | Python training institute in pune

    ReplyDelete
  9. Thank you for sharing such great information with us. I really appreciate everything that you’ve done here and am glad to know that you really care about the world that we live in
    Data Science training in kalyan nagar | Data Science training in OMR

    Data Science training in chennai | Data science training in velachery

    Data science training in tambaram | Data science training in jaya nagar

    ReplyDelete
  10. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    Best AWS Training in Chennai | Amazon Web Services Training in Chennai

    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR


    AWS Training in Chennai |Best Amazon Web Services Training in Chennai


    AWS Training in Velachery | Best AWS Course in Velachery,Chennai

    ReplyDelete
  11. I really like your blog. You make it interesting to read and entertaining at the same time. I cant wait to read more from you.
    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training

    ReplyDelete

  12. Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Nice article on machine Learning

    Machine Learning Training in Hyderabad

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge. c Software Testing Training in Chennai | Software Testing Training in Anna Nagar | Software Testing Training in OMR | Software Testing Training in Porur | Software Testing Training in Tambaram | Software Testing Training in Velachery

    ReplyDelete

  15. The Way Of Explaination Is Very Good And Nice Informative Topic You Have Choosen..
    AWS Course in Hyderabad

    ReplyDelete
  16. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...data scientist courses

    ReplyDelete
  17. Really it is an amazing article I had ever read. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging.
    Angular js Training in Chenai

    Angular js Training in Velachery

    Angular js Training in Tambaram

    Angular js Training in Porur

    Angular js Training in Omr
    Angular js Training in Annanagar

    ReplyDelete
  18. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete
  19. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
    data analytics training in hyderabad

    ReplyDelete