使用 Android Compatibility Package 来简化开发工作

使用 Android Compatibility Package 来简化开发工作



在今年3月份的时候,Android发布了一个被称为”compatibility package“的兼容开发包. 该兼容开发包主要包含了Android最新平台上的最酷的特性,这样的话,当你在为旧版本的Android设备开发程序的时候,就可以使用这个兼容开发包来使用最新的Android特性,而不用自己重新开发, 从而减轻了开发者的开发任务.

其中最常用的2个组件就是ViewPager和Fragment. 例如在Google+ app中信息流中就使用了.效果如下:

使用了TabPager的Google+信息流界面

比如在Android 3.0中包含了几个新加的特性, 这些功能可以通过android compatibility package v4 来在旧版本上使用:

Android 兼容开发包的类库名称(jar包的名称)是”android-support-vX.jar”,其中的”X”代表该兼容开发包支持的最小版本号. 目前只
包含2个版本一个是v4 需要android 1.6以上的系统才能使用; 一个是v13 需要andorid 3.2以上的系统才能使用.

下载Android兼容开发包

通过”Android SDK and AVD Manager”可以下载,具体操作过程:
  1. 启动 SDK and AVD Manager.如果你使用的是Eclipse,可以通过菜单Window>Android SDK and AVD Manager;如果你使用的是Windows操作系统,可以通过sdk目录中的 “SDK Manager.exe"来启动; 如果你使用的是linux系统 可以通过<sdk>/tools 目录中的android脚本来启动.
  2. 选择左边的”Available packages”,然后展开右边的” Android Repository”, 然后选择最下面的”Android Compatibility package” 然后点击右下方的”Install selected”按钮.
  3. 等待安装完成后的提示信息.
使用下载工具(例如 迅雷)自己下载安装:
由于一些众所周知的原因,Google的服务在国*内时不时的不能正常使用, 在下载Andorid开发工具的时候也是如此, 有时候下载了80%了 结果提示下载失败! 如果您经常遇到这种情况或者下载速度很慢, 可以通过其他方式下载.
最新版本的兼容开发包的下载地址是: https://dl-ssl.google.com/android/repository/compatibility_r03.zip大小是541696字节,效验码(sha1)是”49e32c0aca8e52c2e9a398912a68c036583b917f” 下载完后把compatibility_r03.zip 这个文件解压到 <sdk>/extras/android/ 目录下即可. 解压后可以得到一个compatibility目录, 该目录下有各个版本的兼容开发包目录,上面下载的开发包包含2个版本 一个是v4;一个是v13. 每个目录下面分别包含示例代码和开发包的源代码.

如何使用兼容开发包

使用兼容开发包和使用第三方jar包一样,直接添加到项目引用的类库中就可以了:

  1. 在您的andorid项目跟目录中创建一个名称为”libs"的目录
  2. 复制您要使用版本的兼容开发包到libs/目录.支持API Level 4 (Android 1.6)的jar包位于:<sdk>/extras/android/compatibility/v4/android-support-v4.jar.
  3. 把该jar包添加到类路径中.如果您使用Eclipse,只需要在Package Explorer中选中”libs”目录下的”android-support-v4.jar” 然后点击右键, 选中Build Path>Add to Build Path. 添加成功后您会发现该jar包出现到了一个名称为”Referenced Libraries”的节点中.

现在您的app就可以使用兼容开发包了,所有支持的特性都在android.support包中 (例如,android.support.v4).

Tip:如果要更详细的研究这些API如何使用,请参看位于extras/android/compatibility/<version>/samples/ 目录中的示例代码.

参考文档

当前该工具包并没有提供开发文档,但是您可以使用javadoc工具来自己生成, 你可以通过如下步骤来生成v4版本的docs文档:

cd <sdk>/extras/android/compatibility/v4/
mkdir docs
javadoc -sourcepath src/java/ -subpackages android.support.v4 -d docs

使用浏览器打开docs/index.html文件即可查看文档.

更多示例

除了下载的兼容开发包内附带的示例项目外,Google I/O App也是一个使用了该工具的一个示例, 研究下这个项目的代码,可以看看如何在项目中使用兼容开发包.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. Introduction 1.1 Document Structure 1.1.1. Requirements by Device Type 1.1.2. Requirement ID 1.1.3. Requirement ID in Section 2 2. Device Types 2.1 Device Configurations 2.2. Handheld Requirements 2.2.1. Hardware 2.2.2. Multimedia 2.2.3. Software 2.2.4. Performance and Power 2.2.5. Security Model 2.3. Television Requirements 2.3.1. Hardware 2.3.2. Multimedia 2.3.3. Software 2.3.4. Performance and Power 2.4. Watch Requirements 2.4.1. Hardware 2.4.2. Multimedia 2.4.3. Software 2.4.4. Performance and Power 2.5. Automotive Requirements 2.5.1. Hardware 2.5.2. Multimedia 2.5.3. Software 2.5.4. Performance and Power 2.5.5. Security Model 2.6. Tablet Requirements 2.4.1. Hardware 3. Software 3.1. Managed API Compatibility 3.1.1. Android Extensions 3.1.2. Android Library 3.2. Soft API Compatibility 3.2.1. Permissions 3.2.2. Build Parameters 3.2.3. Intent Compatibility 3.2.3.1. Core Application Intents 3.2.3.2. Intent Resolution 3.2.3.3. Intent Namespaces 3.2.3.4. Broadcast Intents 3.2.3.5. Default App Settings 3.2.4. Activities on secondary displays 3.3. Native API Compatibility 3.3.1. Application Binary Interfaces 3.3.2. 32-bit ARM Native Code Compatibility 3.4. Web Compatibility 3.4.1. WebView Compatibility 3.4.2. Browser Compatibility 3.5. API Behavioral Compatibility 3.5.1. Background Restriction 3.6. API Namespaces 3.7. Runtime Compatibility 3.8. User Interface Compatibility 3.8.1. Launcher (Home Screen) 3.8.2. Widgets 3.8.3. Notifications 3.8.3.1. Presentation of Notifications 3.8.3.2. Notification Listener Service 3.8.3.3. DND (Do not Disturb) 3.8.4. Search 3.8.5. Alerts and Toasts 3.8.6. Themes 3.8.7. Live Wallpapers 3.8.8. Activity Switching 3.8.9. Input Management 3.8.10. Lock Screen Media Control 3.8.11. Screen savers (previously Dreams) 3.8.12. Location 3.8.13. Unicode and Font 3.8.14. Multi-windows 3.8.15. Display Cutout 3.9. Device Administration 3.9.1 Device Provisioning 3.9.1.1 Device owner provisioning 3.9.1.2 Managed profile provisioning 3.9.2 Managed Profile Support 3.9.3 Managed User Support 3.10. Accessibility 3.11. Text-to-Speech 3.12. TV Input Framework 3.13. Quick Settings 3.14. Media UI 3.15. Instant Apps 3.16. Companion Device Pairing 3.17. Heavyweight Apps 4. Application Packaging Compatibility 5. Multimedia Compatibility 5.1. Media Codecs 5.1.1. Audio Encoding 5.1.2. Audio Decoding 5.1.3. Audio Codecs Details 5.1.4. Image Encoding 5.1.5. Image Decoding 5.1.6. Image Codecs Details 5.1.7. Video Codecs 5.1.8. Video Codecs List 5.2. Video Encoding 5.2.1. H.263 5.2.2. H-264 5.2.3. VP8 5.2.4. VP9 5.3. Video Decoding 5.3.1. MPEG-2 5.3.2. H.263 5.3.3. MPEG-4 5.3.4. H.264 5.3.5. H.265 (HEVC) 5.3.6. VP8 5.3.7. VP9 5.4. Audio Recording 5.4.1. Raw Audio Capture 5.4.2. Capture for Voice Recognition 5.4.3. Capture for Rerouting of Playback 5.5. Audio Playback 5.5.1. Raw Audio Playback 5.5.2. Audio Effects 5.5.3. Audio Output Volume 5.6. Audio Latency 5.7. Network Protocols 5.8. Secure Media 5.9. Musical Instrument Digital Interface (MIDI) 5.10. Professional Audio 5.11. Capture for Unprocessed 6. Developer Tools and Options Compatibility 6.1. Developer Tools 6.2. Developer Options 7. Hardware Compatibility 7.1. Display and Graphics 7.1.1. Screen Configuration 7.1.1.1. Screen Size and Shape 7.1.1.2. Screen Aspect Ratio 7.1.1.3. Screen Density 7.1.2. Display Metrics

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值