在Android的条件编译? [英] Conditional compiling in Android?

查看:145
本文介绍了在Android的条件编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有Android的任何条件编译的?

Is there any kind of conditional compiling for Android?

我必须让我的项目的Andr​​oid 3.0(API 11)仅仅因为 ExifInterface 的几乎没有有用的属性中的Andr​​oid 2.3(API 10),尽管它出现在API 5(! !?)。我并不想限制我的应用程序ICS用户。

I had to make my project for Android 3 (API 11) just because ExifInterface has almost no useful attributes in Android 2.3 (API 10), despite the fact that it appeared in API 5 (!!??). I don't want to restrict my app to ICS users.

谢谢!

推荐答案

您可以动态地检查设备的当前API版本,并做不同的东西,具体取决于:

You can check dynamically the current API version of the device and do different stuff depending on that:

    if(Build.VERSION.SDK_INT < 14) {
        // Crappy stuff for old devices
    }
    else {
        // Do awesome stuff on ICS
    }

但是要小心,如果你需要实例类,不适用于所有的API,那么你应该做一个可运行,或在一个单独的包装类,如:

But be careful that if you need to instantiate classes that are not available for all APIs then you should do it in a runnable or in a separate wrapper class, e.g:

    if(Build.VERSION.SDK_INT < 14) {
        // Crappy stuff for old devices
    }
    else {
        // Do awesome stuff on ICS
        new Runnable() {
            new AmazingClassAvailableOnICS();
            (...)
        }.run();
    }

这篇关于在Android的条件编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆