If I write an app using Android 4 Platform, will the app work in Android 2 devices?

£可爱£侵袭症+ 提交于 2019-12-05 02:51:45

问题


I want to write an app using Android SDK and Eclipse. I installed Android 4 Platform using the SDK Manager, but I'm wondering, will this app work with Android 2 Devices? or only Android 4 Devices?

Thanks.


回答1:


In your App Manifest XML file you must specify the Minimum and Desired Target SDK version. I am developing a App that Target Android 4.0.3 (SDK v15) but must run on 2.3.3 (SDK v10).

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="15" />

Off course you have to use only the lower SDK available functions. You should also look the Google Support Library thats make available some new functions for older SDK. http://developer.android.com/tools/extras/support-library.html

// Marcello




回答2:


It depends on the system calls you make. Always test on devices running different versions, because certain calls only work for certain API levels.

On the sdk website you can see this info.

(See the "Since: API Level 9" on the right part of the grey bar of the getNumberOfCameras fn)




回答3:


Android Lint is a new tool introduced in ADT r16, which automatically scan and check your project for new API, and show you a nice error mark inside your Eclipse editor.

Rule for checking new API, see here:

NewApi
------
Summary: Finds API accesses to APIs that are not supported in all targeted API
versions

Priority: 6 / 10
Severity: Error
Category: Correctness

This check scans through all the Android API calls in the application and
warns about any calls that are not available on *all* versions targeted by
this application (according to its minimum SDK attribute in the manifest).

If your code is *deliberately* accessing newer APIs, and you have ensured
(e.g. with conditional execution) that this code will only ever be called on a
supported platform, then you can annotate your class or method with the
@TargetApi annotation specifying the local minimum SDK to apply, such
as@TargetApi(11), such that this check considers 11 rather than your manifest
file's minimum SDK as the required API level.

In Eclipse:



来源:https://stackoverflow.com/questions/11321257/if-i-write-an-app-using-android-4-platform-will-the-app-work-in-android-2-devic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!