博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android适配全面总结(二)
阅读量:6967 次
发布时间:2019-06-27

本文共 3119 字,大约阅读时间需要 10 分钟。

上一篇文章讲了 屏幕适配 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 tobe presented to the user using the NotificationManager.The Notification.Builder has been added to make it easierto 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_ICON This constant was deprecated in API level 26. Use getLargeIcon(), which supports a wider variety of icon sources.(在API级别26中已弃用。使用getLargeIcon(),它支持更多种图标源。)

  • EXTRA_SMALL_ICON This constant was deprecated in API level 26. Use getSmallIcon(), which supports a wider variety of icon sources.(在API级别26中已弃用。使用getSmallIcon(),它支持更多种图标源。)

  • FLAG_HIGH_PRIORITY This constant was deprecated in API level 16. Use priority with a positive value.(在api16被弃用,请使用正数priority值替代)

  • FLAG_SHOW_LIGHTS This constant was deprecated in API level 26. use shouldShowLights().(在API级别26中已弃用。请使用 shouldShowLights() 替代)

  • PRIORITY_DEFAULT This constant was deprecated in API level 26. use IMPORTANCE_DEFAULT instead.(在API级别26中已弃用。请使用 IMPORTANCE_DEFAULT 替代)

  • PRIORITY_HIGH This constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.(在API级别26中已弃用。请使用 IMPORTANCE_HIGH 替代)

  • PRIORITY_LOW This constant was deprecated in API level 26. use IMPORTANCE_LOW instead.(在API级别26中已弃用。请使用 IMPORTANCE_LOW 替代)

  • PRIORITY_MAX This constant was deprecated in API level 26. use IMPORTANCE_HIGH instead.(在API级别26中已弃用。请使用 IMPORTANCE_HIGH 替代)

  • PRIORITY_MIN This constant was deprecated in API level 26. use IMPORTANCE_MIN instead.(在API级别26中已弃用。请使用 IMPORTANCE_MIN 替代)

  • STREAM_DEFAULT This 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)替代。

  • largeIcon This field was deprecated in API level 23. Use `setLargeIcon(Icon) instead.

  • ledARGB This field was deprecated in API level 26. use `shouldShowLights().

  • ledOffMS This field was deprecated in API level 26. use `shouldShowLights().

  • ledOnMS This field was deprecated in API level 26. use shouldShowLights().

  • priority This field was deprecated in API level 26. use getImportance() instead.

  • sound This field was deprecated in API level 26. use getSound() instead.

  • vibrate This field was deprecated in API level 26. use getVibrationPattern().

####二、

####三、

####四、

转载地址:http://cfssl.baihongyu.com/

你可能感兴趣的文章
BZOJ 1010: [HNOI2008]玩具装箱toy
查看>>
django之路由分发
查看>>
51nod1832 先序遍历与后序遍历
查看>>
MD5 带salt 加密
查看>>
13 用Css做下拉菜单
查看>>
homework-01
查看>>
修改WAMPServer中MySql中文乱码的方法
查看>>
【下载】推荐一款免费的人脸识别SDK
查看>>
不定参数
查看>>
浏览器各种距离
查看>>
使用Python读取Google Spreadsheet的内容并写入到mangodb
查看>>
DOM操作和jQuery实现选项移动操作
查看>>
[emuch.net]MatrixComputations(1-6)
查看>>
ByteArrayOutputStream用法
查看>>
Floyed那些事~~~~~
查看>>
Python 学习笔记1 安装和IDE
查看>>
H5新增标签
查看>>
日志分析
查看>>
Extract Datasets
查看>>
递归加法运算
查看>>