0

I want to develop an Android application even for android devices with a lower version, while I do not want to sacrifice some available functions in higher versions.

In the AndroidManifest.xml file:

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

I get the android level of the current device:

deviceLevel = android.os.Build.VERSION.SDK_INT;

Then I will use if statements to specify different code for different versions.

if (deviceLevel >= 11) 
{
List<Camera.Size> videoSizes = parameters.getSupportedVideoSizes();
 ......
}
else 
{
 ......
}

However, Eclipse indicates there exists errors. getSupportedVideoSizes is not availabe for version = 8;

I think I need to suppress the error at this situation. How to do that?

user1914692
  • 3,033
  • 5
  • 36
  • 61
  • `@SuppressLint("NewApi")` should supress the new API warnings. Although Eclipse *should* offer to supress it when hovering over the error code. – A--C May 07 '13 at 00:32
  • Thanks. It works! The hint by the Eclipse is in a dark blue font in the black background, which I ignored. I need to modify the format. – user1914692 May 07 '13 at 01:57

2 Answers2

4

You will want to add @SupressLint("NewApi") to your activity class. Then you will want to use android.os.Build.VERSION.SDK_INT; to get the version int, which should always be the API number (ie. Jelly Bean 4.2 is API 17, use 17 for your comparison) or you can use Build.VERSION_CODES.DESSERT_NAME_HERE, and use this value for an if-else to perform your action that can only take place in higher level API's.

TronicZomB
  • 8,667
  • 7
  • 35
  • 50
  • Do you know how to change the font color of the hover window in Eclipse. The reason I ignored the hint by the Eclipse is that the dark blue font in the black background really is easy to be ignored. – user1914692 May 07 '13 at 03:48
0

I think it will be better if you change "minSdkVersion" to 15. Because it will easily die when run at pervious device.

  • Then the app won't be able to be installed on anything less than SDK 15. – A--C May 07 '13 at 01:09
  • I konw, I know. Although it is may be installed, the experience won't be good. – fabuler_cn May 07 '13 at 01:20
  • There is no reason to set the `minSdkVersion` to 15. OP can just use an if-else to prevent a crash. This isn't really that great of advice. If the OP wants to add a new feature that is only available on newer OS versions, but the app still is fully functional on older versions then there is no reason to cut out that whole user base just because they won't get the new feature that can be handled in an if-else. – TronicZomB May 07 '13 at 01:48
  • @fabuler_cn no probs. That's what this community is about, attempting, trying, and learning from it. – TronicZomB May 07 '13 at 01:57
  • What is the meaning of 'no probs'? My English is not very good. – fabuler_cn May 08 '13 at 01:55