You need to check if the needed API is supported. This can be done as follows:
//Feature is supported. Do something.
//feature was not supported.
You can check the property microedition.platform, something like:
/// 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.
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.