I have developed an application in Android. It works for all users except KitKat users. When I upload this app in Play Store, I want the KitKat users not to be able to download this app. Even when I was executing this app in my system, it was detecting KitKat mobiles. I have tried using android:maxSdkVersion="18"
in Android manifest file, but it was not possible.
Is there any way to do it?
It depends on what exactly you want. According to the documentation for the deprecated maxSdkVersion:
Future versions of Android (beyond Android 2.0.1) will no longer check or enforce the maxSdkVersion attribute during installation or re-validation. Google Play will continue to use the attribute as a filter, however, when presenting users with applications available for download.
So, users could still sideload the app, but it will not appear in Google Play for users above that level. That sounds like what you want. There is no way(since 2.0.1) to completely disable sideloads.
Regarding this note about compilation:
...and the SDK will not compile if maxSdkVersion is set in an app's manifest.
I had my doubts. After testing it just now, my Eclipse/ADT compiles just fine with maxSdkVersion=15 set. So I wouldn't worry about that.
The answers regarding targetSdkVersion are fine for some things, but if you're using something that was intentionally broken/changed in a newer API, they won't work at all. For example, no amount of compatibility mode will allow 4.2+ to turn airplane mode on/off programmatically from within a non-root app. It also won't change the new implementation of SecureRandom.
If the app really is just completely useless for 4.4 because a key feature was removed, try using maxSdkVersion. Using a deprecated method always leaves me with a bad taste, but if they don't offer any sort of functional replacement, sometimes it's the only choice.
Like it says in http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#max, setting the maxSdkVersion does filter it in Google Play, so it won't be seen by devices above that level. That's the only place that checks it, though. Side-loading will still be possible.
The only real problem you'll run into is with people upgrading their OS. If they downloaded it from Play with 4.3, and later upgrade to 4.2, the app won't work correctly.
For those users(and side-loaders), you may want to do a version check on startup. If they fail the check, gracefully tell them what happened in a dialog, etc. Much better than an invisible "it doesn't work anymore!"
However, if you can work around it by changing how you accomplish , that is by far the best solution.
Thanks.