Is there a way to use features in Android 2.1/2.2 while keeping a minSDK version to 3?

前端 未结 1 1202
攒了一身酷
攒了一身酷 2021-01-05 10:03

I have a project that is just using Android 1.5 for programming, but with the proliferation of other handsets and some cool features in Android 2.2, we\'d like to support th

1条回答
  •  太阳男子
    2021-01-05 10:35

    we'd like to support the features without losing support for 1.5 or forking a new code base. Is it possible to do with Android SDK?

    Sure. The techniques have been around for about a decade or so.

    Option #1: Use reflection to access new classes (or new methods of existing classes) at runtime. See here for an example.

    Option #2: Use conditional class loading, by creating an interface plus two implementations (one for an older API, one for a newer API), and loading the right implementation at runtime. Since the newer implementation will not be loaded on a older device, the fact that the newer implementation uses classes or methods that the older device lacks will not pose a problem. See here for an example.

    0 讨论(0)
提交回复
热议问题