Package javax.microedition.contactless.visual

Provides means to read information stored on visual tags (bar codes) and to generate visual tag images.

See:
          Description

Interface Summary
ImageProperties This interface collects the properties of visual tag image that are common to all symbologies.
VisualTagConnection This interface provides contactless connection to a visual tag (bar code) target.
 

Class Summary
SymbologyManager This class is a starting point when using visual tags.
 

Exception Summary
VisualTagCodingException This exception captures the error situations related to encoding and decoding errors in visual tag reading and image generation.
 

Package javax.microedition.contactless.visual Description

Provides means to read information stored on visual tags (bar codes) and to generate visual tag images.

Package Specification

This package contains the functionality that allows contactless communication with visual tag targets. It contains interfaces and classes needed to read information stored on the visual tags. The package also includes a mechanism to generate visual tag images using specified symbologies.

There are a lot of different visual tag symbologies. Some of them are proprietary and some are available in the public domain as standardized specifications. This specification does not mandate the use of certain symbologies, since different symbologies are required in the different applications domains. Therefore it only provides a method for querying a list of symbologies that are supported for reading and for visual tag image generation by the API implementation.

Visual tags are treated as any contactless target in this specification. They can be discovered through the DiscoveryManager interface, but a connection to them can also be opened manually. The URL needed to open a manual connection to the visual tag is described in VisualTagConnection interface. After the connection is opened, the developer can read visual tags or generate visual tag images.

The following example code shows how a connection to a visual tag can be opened manually to read a visual tag and generate a visual tag image. First the connection to a visual tag is opened manually. After that the data from the visual tag is read using Code 39 symbology. After that it generates a visual tag image with text "test" using Code 39 symbology in encoding.

import java.io.IOException;
import javax.microedition.contactless.ContactlessException;
import javax.microedition.contactless.visual.*;
import javax.microedition.io.Connector;

/**
 * Example class of how to read visual tags and generate visual tag
 * images using JSR 257 Contactless Communication API
 */
public class TestVisual {

    private String mySymbology ="Code 39";

    public TestVisual() {
        readVisualTag();
        generateVisualTag();
    }
    
    public void readVisualTag() {
        boolean supported = false;
        
        try {
            // Check that needed symbology is supported for reading
            String[] symbologies = SymbologyManager.getReadSymbologies();
            for (int i=0; i<symbologies.length; i++) {
                if (symbologies[i].equals(mySymbology)) {
                    supported = true;
                    break;
                }
            }
            if (supported) {
                // Get supported image classes
                Class[] images = SymbologyManager.getImageClasses();
                // Get the visual tag image
                Object image = getImage();
                // Read visual tag
                VisualTagConnection conn = 
                    (VisualTagConnection)Connector.open("vtag://");
                byte[] data = conn.readVisualTag(image, images[0], mySymbology);
                // Handle data from the image
                conn.close();
            }
            else {
                System.out.println("Symbology not supported for reading");
            }

        }
        catch (IOException ioe) {
            // handle exception
        }
        catch (VisualTagCodingException ce) {
            // handle exception
        }
    }
  
    public void generateVisualTag() {
        boolean supported = false;
        
        try {
            // Check that needed symbology is supported for image generation
            String[] symbologies = SymbologyManager.getGenerateSymbologies();
            for (int i=0; i<symbologies.length; i++) {
                if (symbologies[i].equals(mySymbology)) {
                    supported = true;
                    break;
                }
            }
            if (supported == true) {
                // Get properties for code 39 symbology
                ImageProperties properties =
                    SymbologyManager.getImageProperties(mySymbology);
                // Get supported image classes
                Class[] images = SymbologyManager.getImageClasses();
                int i;
                for (i=0; i<images.length; i++) {
                    if (images[i].equals("javax.microedition.lcdui.Image")) {
                        // LCDUI Image supported
                        break;
                    }
                }
                // Generate visual tag image
                VisualTagConnection conn = 
                    (VisualTagConnection)Connector.open("vtag://");
                byte[] data = "test".getBytes("UTF-8");
                Object vtagImage  = conn.generateVisualTag(
                        data, images[i], properties);
                Image img = (javax.microedition.lcdui.Image)vtagImage;
                ...
            }
        } 
        catch (ContactlessException ce) {
            // handle exception
        }
        catch (IOException ioe) {
            // handle exception
        }
    }
}
                



Copyright © 2005-2006 Nokia Corporation. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.