开发者

J2ME do cellphones have an auto-disable feature for non-compatible Packages?

开发者 https://www.devze.com 2023-03-27 23:00 出处:网络
I\'d like to know if, for instance, I develop an App with both WMA Packages (1.1 and 2.0) and then deploy it to an older phone model with only WMA 1.1 support, will the Phone disable the 2.0 Package?

I'd like to know if, for instance, I develop an App with both WMA Packages (1.1 and 2.0) and then deploy it to an older phone model with only WMA 1.1 support, will the Phone disable the 2.0 Package?

The code doesn't differ for wha开发者_如何学Got it's set to do between packages, but the 2.0 package gives extra functionality to that code which ends up being optimal for more recent phones.


I'd consider using Class.forName to load appropriate code depending on whether device supports WMA 2 or not

class SpecificFeatureFactory {
    SpecificFeature get(boolean isWma2) {
        return (SpecificFeature)Class.forName(isWma2 ? "Rich" : "Poor");
    }
}

class Rich implements SpecificFeature {
    @Override
    long doSomething(String className, Date dateAlarm) throws Exception {
        return PushRegistry.registerAlarm(className, dateAlarm);
    }
}

class Poor implements SpecificFeature {
    @Override
    long doSomething(String className, Date dateAlarm) throws Exception {
        return -1;
    }
}

interface SpecificFeature {
    long doSomething(String className, Date dateAlarm) throws Exception;
}

Per my recollection WMA spec describes how application can determine whether it's 1.1 or 2.0.


It will be an error on the older phone, that does not support new functionality.

Use Preprocessor to compile different versions for old and new phones from one package of source code.


If size isn't an issue you don't have to necessarily use preprocessing. If you don't use classes that are only present in WMA 2.0 you will just be tripping on NoSuchMethodErrors. Consider doing this.

public void doSomeThing()
{
  try{
    callWMA2_0Method();
  }
  catch( NoSuchMethodError e )
  {
    // We're WMA 1.1 then 
    callWMA1_1Method();
  }
} 

You can of course only compile against WMA 2.0 of course. But that shouldn't be a problem

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号