Android - multiple SDK support in one project? - android

I'm creating an app that uses the clipboard manager. Since the way of working with this has changed since API level 10 but I still want it to work on all versions, I would like to use both APIs if possible. I would then like to code some kind logic like this:
if androidVersion < 10
use code x
else
use code y
Is this possible?
When I create a project in Eclipse, it either gives me the Android 1.6 jar file or the Android 3.0 jar file depending on the min SDK version I selected. My question is if it's possible to import and use both and if so how? Or will I simply need to make separate projects for different versions? Thanks.

Is this possible?
Sure. Use android.os.Build.VERSION to find out what version you are running on and use the appropriate code based upon that.
If you are supporting Android 1.x, the story gets a bit more complicated.
When I create a project in Eclipse, it either gives me the Android 1.6 jar file or the Android 3.0 jar file depending on the min SDK version I selected.
No, it does not. It gives you 1.6, 3.0, or whatever based on the build target you selected. By default, it also makes the android:minSdkVersion match that, but you can change that, so the minSdkVersion is the oldest that you are willing to support and the build target is the oldest whose APIs you are directly referencing.
My question is if it's possible to import and use both and if so how?
You do not need to import both, and you can't do that anyway.
Or will I simply need to make separate projects for different versions?
You do not need separate versions.

Related

Does Material Design Library work with eclipse?

I googled for this purpose but I couldn't find any answer for my question but I found Android Material Design with android studio , my question here is there any way to add Material Design Library to my android project in Eclipse.
thanks for any comment.
Obviously it does.
It doesn't depend on the IDE, Check out this.
It's in German, but it's all pictures, so, it's very easy to follow even if you don't know German.
Mind that you must have the SDK installed (21+). Simply do all the upgrades in the SDK Manager, then (when finished) Help/Check for Updates in Eclipse.
To make the newer SDK design apps work on lower level devices, you must set the minSDKVersion to the lowest API Level you want to support.
And use the support.library versions of the objects and the methods.
i.e.:
Use NotificationCompat instead of Notification
Use getSupportFragmentManager() instead of getFragmentManager(), ...

Does android 4.2.2 have CacheManager?

My old android project(with sdk 2.2.3) cannot be compiled with sdk 4.2.2, because it seems that 4.2.2 does not have "android.webkit.CacheManager".
So how would I solve it? What can be its replacement?
It seems that CacheManager was deprecated in API level 11, and the following commit in Android 4.2.1_r1 shows that many of its APIs were removed.
A basic implementation of a replacement would be to save the file locally, along with a tag specifying the last used time. Then, after a (certain) period of time, check if the asset is too old and delete it, if true.
This article and this article seem to provide with example implementations. There are also plenty of libraries, as this one.

Android API Level requirement

I'm using DragShadowBuilder in my application. http://developer.android.com/reference/android/view/View.DragShadowBuilder.html
In AndroidManifest, I've set the minimum supported API level to 8. However, DragShadowBuilder was introduced with API 11. Eclipse usually warns me when something is below the minimum API level, but it seems fine with me using DragShadowBuilder. Should I be included some support library or something along those lines to ensure that the code runs on older versions of Android?
No your code may not run in older version of Android. You may want to write Drag logic of your own using AbsoluteLayout, if at all if you want to achieve drag feature in older versions. Hope it helps
I believe this is a bug with Eclipse. I would suggest that you simply make the minimum supported API level to 11. AFAIK, you could always create it to support API 11 first, and then try to recreate it with a new project and by adding the library you want.
I have tried this and if you were to create a new project, set it to a lower API, import a "Drag and Drop" like library, and try to write the code for it, you will most likely get an error saying that it won't work and/or that the Drag and Drop function is set for API's 11. If you Clean the project after, the error might "disappear" go away but once you try to run the application, it will reappear and say that it can't run with errors.
It is weird even though you have the library embedded with the code. Perhaps you could try renaming the classes and such if the machine can not differentiate which "DragEvent" you are trying to call forth.
I just looked through the published contents of what is in the library and I didn't see anything about DragShadowBuilder.
You can check the contents of what's in there at http://developer.android.com/tools/extras/support-library.html
I also looked in the source some and didn't see anything mention about it. How do I attach the Android Support Library source in Eclipse?
If there is no backwards support then you are basically on your own for this. You can also look at the source for DragShadowBuilder and try to recreate that in your application.

Converting Android version 2.3 to 1.5

I have developed one application in Android version 2.3, and want to convert it into 1.5.
Unfortunately I am experiencing some problem with that.
I have changed minSDK from 8 to 5
changed from property
But I still get the problem.
Any ideas?
There are several aspects to converting an application's version number.
The later the Android version, the more features are supported. Features are things like front-facing camera support, NFC support, Fragments or Drag and drop.
If you plan to convert an application, make sure that the target version supports the features you need. This describes the major differences between the various API levels.
The Android API is updated with each new Android version. This means that methods, constants and attributes can be available on some API levels, but not on others. To see what is available in which API level, go to the android documentation and in the upper right corner select 'filter by api level'. Then select an API level. After you do that all API features that weren't available in the selected API level will be grayed out making it easy to identify the available elements. If your code contains elements that don't exist in the targeted level, you will get errors.
You need to explicitly specify the Android version in two(!) places in Eclipse.
To change the API level of an Android project in Eclipse:
a. Open the project manifest and change the minSdkVersion:
b. Open Properties -> Android, and change the Project Build Target (API level).
Finish by cleaning your project (Project -> Clean...) to ensure that the project references are updated.
After doing this, any features (methods, constants, attributes, etc.) not available in the updated API level will show up as errors in your project.
To fix these errors, Google
android < feature> < API level>
which will often lead you to replacement code.
After re-reading the question I believe I've found the specific mistake:
You say you've set the minSdkVersion to 5. API level 5 corresponds to Android version 2.0.
You also say you want to convert your project to Android version 1.5, which leads me to believe that you've set your Project Build Target to the corresponding API level 3.
If you change either of those to match the other, your original problem should be solved.
In order:
change the minSDKattribute in your manifest
edit project properties and change the target platform, to ensure you rely on the good library
do a Project > Clean to ensure, to ensure you don't have old constants in R.java or binary code compiled for a future platform
fix your project
optionnaly, place back some future code, like move to SD feature in the manifest
To convert backward means that you have to write alternative code to replace method for api you used in the higher version SDK=8 that aren't supported in the old SDK=5, because in the old version those methods won't exist.
It is better if you plan ahead witch minimum version to support.
Right click the project in eclipse, go to Properties, go to android, and set the build target to 1.5.
If you have used any inbuild functions or methods or constants or attributes that was added after the release of android 1.5 and if you try to change to 1.5 now, you will not be able to do that. Make sure that you have not used such kind of methods or any other attributes that was not released in 1.5.

Choosing the right API Level for my android application

I currently have a application targeted at android 2.3 (api level 10), but went thinking that probably people using android 2.1/2.2 or older won't even be able to see the application in the market.
So I thought that using api level 3 would be the best to use, but I don't know if this will maybe make certain elements in my app work less good, and probably buggier, since it actually uses old android code. Is there a good way to find out which API level I should use, and also, how do I convert my application to that level?
You can find a breakdown of the different versions of Android in use here. Currently, if you target 2.1 (API 7) you'll only miss out on about 3% of the market. Targeting 2.2 will miss just under 20%, or a fifth of the market.
As for converting your app, you can check what API level things are available for in the Android Reference. You'll note a checkbox and dropdown menu on the top right of the browsing area that allows you to filter by API level - that's one way to help converting. The other is to set the target and minimum SDK versions which will help Eclipse know what to complain about in your code. The easiest way to see if something needs conversion, however, is to emulate and test.
EDIT: The API level dropdown moved from the top right to the top left, over the list of APIs.
This graph may help you make up your mind.
It is good to look at backward compatibility and in general, you should compile your application against the lowest possible version of the platform that your application can support.
You can determine the lowest possible platform version by compiling the application against successively lower build targets. After you determine the lowest version, you should create an AVD using the corresponding platform version (and API Level) and fully test your application. Make sure to declare a android:minSdkVersion attribute in the application's manifest and set its value to the API Level of the platform version. Good luck!
If you have
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="10"/>
then it will appear right down to 1.6, but make sure you don't use antyhing that they don't have in their API
edit: Don't bother with 3! :)
I started out developing for 1.5, but soon realized that only a small percentage of people still run 1.5. I generally develop at the 2.1 level, and leave it at that (unless you need features at a higher level). To change it, open your project properties, and while I don't have my environment open, there is an Android option where you will select what API level you want to target.
The Best API Level is contains follows
1) The best API covers 100% market but all are not prefect so our app should be covered at least 90% with all devices .
2)We have to care about backward compatibility issues and our code would adapt itself for upcoming versions.
3) Using the new Android SDK is a requirement to use any of the new APIs added in that level. It should be emphasized ... It is ultimately a business decision on whether supporting an additional 3% of devices is worth the development and testing .
4) check out this link https://developer.android.com/guide/practices/compatibility.html#defined
5) Finally choose the best API you will find best API

Categories

Resources