Why is java.text.Normalizer available on my Android 2.2 phone?

倖福魔咒の 提交于 2019-12-23 04:00:07

问题


This thing baffle me...

I was checking my code, and decided to change the build target from 2.3 to 2.2 to make sure every 2.3 API that I use is wrapped in a nice android.os.Build.VERSION.SDK_INT check.

But somewhere I make a call to java.text.Normalizer.normalize() that does not check for the SDK version. Curious as why this wasn't found by QA, I started the app on a 2.2 phone in debug mode and it works fine!

The phone is a LG-P505R version 2.2.2.

So, why does this 2.2 phone can call some API that were added in 2.3?

The only logical explanation that I could think of is that the manufacturer has added this API to the Android stack.


[Update] More madness...

I tested this code on a 2.2. emulator and it works fine:

public class NormalizerTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final String s = "This \"é\" will become an \"e\"";

        final TextView tv = (TextView) findViewById(R.id.tv);

        final String temp = Normalizer.normalize(s, Normalizer.Form.NFD);
        final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
        final String strNormalized = pattern.matcher(temp).replaceAll("");

        tv.setText(strNormalized);
    }
}


回答1:


So for now my only guess is that it was made public in 2.3, but it was there all along...




回答2:


Confirmed That java.text.Normalizer works perfectly in a vanilla API8 emulator. Just have to add lint error suppression to the code to get eclipse to compile.



来源:https://stackoverflow.com/questions/8185332/why-is-java-text-normalizer-available-on-my-android-2-2-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!