上一篇文章讲了 屏幕适配 http://www.jianshu.com/p/7aa34434ad4d
这一篇文章讲一下 版本适配。

*在我们的开发中,会对不同安卓版本做适配,比如我之前做过的项目中最低兼容到4.4,最高兼容是最新的系统7.1,由于不同版本的系统中部分API版本也不同,我就要对这些API做特殊处理。新的平台有一些API不能使用旧的API,旧的平台也使用不了新的API。所以这就要考验我们开发人员的能力了。我这里简单给出几点我开发中使用过的一些方式,仅供参考:
####一、同一个api在不同版本都存在,只是api的一些接口方法有变更。
这种情况是最好处理的,只要对版本号做判断,对应的系统版本用相应的api方法就好了。为了好维护,建议做一个简单的封装。
举例说明如下:
比如Notification在不同版本的兼容,举例如下:
首先打开谷歌官方文档,看看文档里面的一些说明:
1.Notification这个类是added in API level 1,一直都有,只是具体某些方法有变更。继续往下看。
2.这个类有个说明,意思是Notification.Builder是新增的一个内部类,用它创建通知更方便。接着往下看。
A class that represents how a persistent notification is to
be presented to the user using the NotificationManager.
The Notification.Builder has been added to make it easier
to construct Notifications.
3.Public constructors公共的构造方法,其中有3个参数的这个在api 11过时,它被Notification.Builder替代了。
Notification(int icon, CharSequence tickerText, long when)
This constructor was deprecated in API level 11.
Use Notification.Builder instead.
4.常量
-
EXTRA_LARGE_ICONThis constant was deprecated in API level 26. Use getLargeIcon(), which supports a wider variety of icon sources.(在API级别26中已弃用。使用getLargeIcon(),它支持更多种图标源。) -
EXTRA_SMALL_ICONThis constant was deprecated in API level 26. Use getSmallIcon(), which supports a wider variety of icon sources.(在API级别26中已弃用。使用getSmallIcon(),它支持更多种图标源。) -
FLAG_HIGH_PRIORITYThis constant was deprecated in API level 16. Use priority with a positive value.(在api16被弃用,请使用正数priority值替代) -
FLAG_SHOW_LIGHTSThis constant was deprecated in API level 26. use shouldShowLights().(在API级别26中已弃用。请使用shouldShowLights()替代) -
PRIORITY_DEFAULTThis constant was deprecated in API level 26. use IMPORTANCE_DEFAULT instead.(在API级别26中已弃用。请使用IMPORTANCE_DEFAULT替代) -
PRIORITY_HIGHThis constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.(在API级别26中已弃用。请使用IMPORTANCE_HIGH替代) -
PRIORITY_LOWThis constant was deprecated in API level 26. use IMPORTANCE_LOW instead.(在API级别26中已弃用。请使用IMPORTANCE_LOW替代) -
PRIORITY_MAXThis constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.(在API级别26中已弃用。请使用IMPORTANCE_HIGH替代) -
PRIORITY_MINThis constant was deprecated in API level 26. use IMPORTANCE_MIN instead.(在API级别26中已弃用。请使用IMPORTANCE_MIN替代) -
STREAM_DEFAULTThis constant was deprecated in API level 21. Use getAudioAttributes() instead.(在API级别21中已弃用。请使用getAudioAttributes()替代)
5.字段Fields
-
audioAttributes在api 26弃用. 使用getAudioAttributes()替代. -
audioStreamType在api 21弃用. 使用audioAttributes替代. -
defaults此字段在API 26弃用。使用getSound()和shouldShowLights()和shouldVibrate()。 -
icon此字段已在API级别26中弃用。使用setSmallIcon(Icon)替代。 -
largeIconThis field was deprecated in API level 23. Use `setLargeIcon(Icon) instead. -
ledARGBThis field was deprecated in API level 26. use `shouldShowLights(). -
ledOffMSThis field was deprecated in API level 26. use `shouldShowLights(). -
ledOnMSThis field was deprecated in API level 26. useshouldShowLights(). -
priorityThis field was deprecated in API level 26. usegetImportance()instead. -
soundThis field was deprecated in API level 26. usegetSound()instead. -
vibrateThis field was deprecated in API level 26. usegetVibrationPattern().
####二、
####三、
####四、
