---
title: "Android 2.2兼容性移植"
author: "ofy28ofy"
date: "2012-01-20T02:52:13Z"
tags: []
categories: ["非技术"]
slug: "android-2-2"
draft: false
lastmod: "2012-01-20T02:52:13Z"
id: 1361972
url: "https://ofy28ofy.iteye.com/blog/1361972"
---


Android 2.2兼容性移植 
2011年05月04日
　　1. 文件系统，大多数网友可能发现/sdcard/的路径已经变为/mnt/sdcard/了，所以过去硬编码相关的软件需要通过 android.os.Environment.getExternalStorageDirectory ().getAbsolutePath()这样 的方法来获取sdcard路径。 
　　2. app2sd，这项功能，可以在settings中开关设置启用，PackageManager类多了一些新的标记，为了兼容性我们使用反射动态调用比较 可靠，判断API Level的方法为Build.VERSION.SDK，注意这是String类型的，返回直接为数字，比如返回8为Android 2.2。 
　　3. GPS开关，很多LBS的应用我们需要开关GPS，在Android 1.5开始GPS的开关方法又有了新的方式，而考虑到安全系统引入的android.provider.Settings.Secure包，有关GPS的 开关可以使用setLocationProviderEnabled(ContentResolver cr, String provider, boolean enabled) ，Android123提示这方法在API Level为8以前并不公开，通过编译Android Framework或反射在部分机器调用时需要OEM的签名才能正常工作。 
　　4. fill_parent改名为match_parent，不过这样看起来没有过去形象，有关Android 2.2的改进，还是希望大家关注Android开发网的移植板块。 
　　http://tonyyu.iteye.com/blog/753466 
