You Are Here:

Community: Developer Discussion Boards

#1 Old Accessing device info - 2002-05-22, 09:45

Join Date: Mar 2003
Posts: 2
dgiel
Offline
Registered User
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
Reply With Quote

#2 Old RE: Accessing device info - 2002-05-22, 10:10

Join Date: Mar 2003
Posts: 46
petri24
Offline
Registered User
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
Reply With Quote

#3 Old RE: Accessing device info - 2002-05-22, 11:49

Join Date: Mar 2003
Posts: 231
Location: UK
LongSteve
Offline
Regular Contributor
Hi,

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

if(System.getProperty("microedition.platform").equals("6310i")) {
/// 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
Reply With Quote

#4 Old RE: Accessing device info - 2002-05-22, 13:58

Join Date: Mar 2003
Posts: 2
dgiel
Offline
Registered User
Thanks, Steve,
your method of using Systems.getproperty("microedition.platform")
is working fine; on my emulator, I get the return string "Nokia6310i/02.20" and I
guess that using .startsWith("Nokia6310") will yield reasonable
results in real life.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia