Main.java

/**
 * Copyright (c) 2013 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */
package com.nokia.example.nnaclientexample;

import javax.microedition.content.*;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;


/**
 * The application main class.
 */
public class Main 
			 extends MIDlet 
			 implements RequestListener {
	
    ContentHandlerServer handlerServer;
    private MainView mainView;

    /**
     * Constructor.
     */
    public Main() {
        try {
            //Registering to receive JSR-211 invocations
            handlerServer = Registry.getServer(this.getClass().getName());
            handlerServer.setListener(this);
        }
        catch (ContentHandlerException ex) {
            System.out.println("JSR-211 exception caught: " + ex.getErrorCode());
        }
    }

    /**
     * @see javax.microedition.midlet.MIDlet#startApp()
     */
    public void startApp() {
        mainView = new MainView(this);
        Display.getDisplay(this).setCurrent(mainView);
    }

    /**
     * @see javax.microedition.midlet.MIDlet#pauseApp()
     */
    public void pauseApp() {
    }

    /**
     * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
     */
    public void destroyApp(boolean unconditional) {
    }

    /**
     * Quits the application.
     */
    public void quit() {
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * @see javax.microedition.content.RequestListener#invocationRequestNotify
     */
    public void invocationRequestNotify(ContentHandlerServer handler) {
        Invocation invoc = handler.getRequest(false);

        if (invoc != null) {
            String key = "";
            String value = "";

            if ((invoc.getArgs() != null) && (invoc.getArgs().length > 0)) {
                String temp = invoc.getArgs()[0];
                int idx = temp.indexOf("=");

                if (idx > 0) {
                    key = temp.substring(0, idx);
                    value = temp.substring(idx + 1);
                }
            }
            
            if (mainView != null) {
                mainView.setPressedItemId(value);
                mainView.addLogMessage(MainView.INVOCATION_RECEIVED, "JSR-211 invocation action: " + invoc.getAction());
                mainView.addLogMessage(MainView.INVOCATION_RECEIVED, "Invocation arguments were: key: " + key + " & value:" + value);
            }
        }

        handlerServer.finish(invoc, Invocation.OK);
    }
}

Last updated 9 October 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×