I want to import facebook libraries for blackberry 5.0 and above and don't want to import those libraries for 4.6 and 4.7.
I tried to use preprocessors for 4.7 and above by following below link: http://smartfone-more.blogspot.in/2010/05/coding-for-multiple-blackberry-devices.html
now its working fine with JDE 4.7 but not getting expected result for 5.0. Please find the code below which i tried:
//#ifdef JDE_4_7_0
import net.rim.device.api.ui.component.ButtonField;
//#else
import net.rim.device.api.ui.component.LabelField;
//#endif
import net.rim.device.api.ui.container.MainScreen;
public class TestScreen extends MainScreen{
TestScreen(){
//#ifdef JDE_4_7_0
ButtonField btn = new ButtonField("Test Button");
add(btn);
//#else
LabelField lbl1 = new LabelField("Test Label 1");
add(lbl1);
//#endif
}
}
As per the code i am expecting the result written in else part for 5.0 and if part for 4.7. I checked it on device as well as JDE both.
Please Help.
First of all, the
JDE_4_7_0
tag is a custom tag you should define in BlackBerry project properties -> "Compile" tab -> preprocessor defines. You can give it the name you wish.Second, in your source file, the first line (even before package declaration) should be:
Then, when you want to disable the conditional import, go back to the "preprocessor defines" tab and remove the
JDE_4_7_0
entry. That will make the compiler enter the#else
clause. The BB plugin for eclipse does not detect the OS, it is all an artifact you should control.EDIT:
You'll end with two sets of deliverables, one for 5.0+ and the other for 4.x. BBant tools allows you to perform the compilation process in one step, but the product of the compilation will be the same. As an alternative, you can:
DeviceInfo.getSoftwareVersion
orDeviceInfo.getPlatformVersion
.Using this approach you might be able to have a single app compatible with 4.6+ devices, and only 5.0+ ones will use fb sdk.
*NOTE: I don't know why that facebook blackberry sdk is compiled for 5.0. Maybe the author just used the lower OS he had in his development machine, who knows. But without testing it I cannot state it is 4.5 compatible, just that the jar is 4.5 compilable.
Change the directive name to something more like
JDE_4_7_0_OR_HIGHER
, then go into your project's Blackberry_App_Descriptor.xml file and addJDE_4_7_0_OR_HIGHER
to the "Preprocess Directives" list, and then make sure it is enabled whenever you compile the project with a JRE version that is 4.7 or higher (you can install multiple JREs and then select a specific one in the project options before compiling). Then your code will look like this: