×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Accessing device info

    I am currently writing code for MIDlet-compliant device. Now I want
    to access NOKIA-specific APIs as well _IF_ the device on onto which the code was loaded actually is capable to use them:

    {
    boolean nokia=false;
    nokia=checkNokia6310();
    if(nokia)
    {
    Sound sound1=new Sound(2200,50);
    sound1.play(1);
    }
    else
    {
    // Sorry no beep
    }
    }
    private void checkNokia6310()
    {
    ???
    }

    Can someone please give me a hint how '???' looks like?
    Thanks

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    46

    RE: Accessing device info

    hi,
    You need to check if the needed API is supported. This can be done as follows:
    try
    {
    Class.forName("com.nokia.mid.sound.Sound"
    //Feature is supported. Do something.
    }
    catch(Exception e)
    {
    //feature was not supported.
    //Do something.
    }

    regards,

    Petri/Forum Nokia

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: Accessing device info

    Hi,

    You can check the property microedition.platform, something like:

    if(System.getProperty("microedition.platform&quot.equals("6310i&quot) {
    /// Do 6310i stuff
    }

    I don't know exactly what the string to test against is, and it probably isn't just "6310i", so you'll need to do some experimenting to see what to look for.

    I don't know how much luck you'll have trying to write generic code if you want to use any vendor specific APIs. Class.forName does *not* work in the J2ME environment. Any type of dynamic class loading is forbidden, and the forName method is not even available on the Class class.
    You might be able to use a try/catch block and catch ClassNotFoundException around the Sound calls, and if the Sound class is not found then obviously it's not available.

    It may be the case though that your application will not even install on a non-Nokia device if you've used the Nokia API in your code. The pre-verification and/or the device class loader might reject your class because it cannot resolve the reference to Sound.

    I think it's dangerous to assume something like this will work on all devices, and in the end, the only option is to produce a different package for each device you want to target.

    In terms of source code though, I've used a C preprocessor quite sucessfully on Java source files. That way you can have common source for multiple J2ME platforms, along with an appropriate build process to produce packages for each one.

    Cheers,
    Steve

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    RE: Accessing device info

    Thanks, Steve,
    your method of using Systems.getproperty("microedition.platform&quot
    is working fine; on my emulator, I get the return string "Nokia6310i/02.20" and I
    guess that using .startsWith("Nokia6310&quot will yield reasonable
    results in real life.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •