17

I developed a application for Android 3.0, and it's runs perfectly well, but the client insist on compatibility with 2.2 devices.

Disabling hardware acceleration, using Android Compatibility Package, a NIO-backport support (For tasks and executors) and some reimplementation of View methods I was able to port my app for Android 2.2 and works really good, but if I run this apk into a newer device the performance is extremely slowly, so I want to know how to turn on hardware acceleration if available but still uses my 2.2 APK.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167

3 Answers3

30

Add android:hardwareAccelerated="true" to your manifest, either for the <activity> or the <application>.

This attribute will be ignored on older versions of Android, but will be honored on Android 3.0+.

This will require you to have set your build target to API Level 11 or higher, but you probably already have that.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    The build target is 8 so it can run on Android 2.2 devices. Just adding android:hardwareAccelerated="true" with minSdk=8 give errors. – Marcos Vasconcelos Apr 26 '12 at 19:51
  • 1
    @MarcosVasconcelos: The build target has nothing whatsoever to do with what devices it can run on. – CommonsWare Apr 26 '12 at 19:59
  • True, it's really doesn't matter which build target it's points, since minSdkVersion is respected. – Marcos Vasconcelos May 08 '12 at 18:44
  • so if you put the API level to 11 or higher with minSdk=8 and you publish your app, it's gonna be available for android 2.2 users? – Alexis May 24 '12 at 13:38
  • Although not important as the question, i wonder how would you suppress the warnings for XML? – Buddy Aug 16 '15 at 18:17
  • @EnesBattal: Sorry, but I do not know what warnings you are referring to. You may wish to ask a fresh Stack Overflow question, where you show your XML and show your warnings. – CommonsWare Aug 16 '15 at 18:20
3

If you need support devises with old OS (2.3.X and older) version, not add android:hardwareAccelerated="true" to your manifest, try add this code in your java:

try { if( Build.VERSION.SDK_INT >= 11) getWindow().setFlags( 16777216, 16777216); } catch( Exception e) {} // FLAG_HARDWARE_ACCELERATED == 16777216 (0x01000000)

This is work in OS 3.0++ and not call error on 2.3.X and older.

Tapa Save
  • 4,769
  • 5
  • 32
  • 54
2

You can look here to see how you can enable features based on Android version. You can do it with reflection too, but it is clunky.

omermuhammed
  • 7,365
  • 4
  • 27
  • 40