Using multiple sdk versions in my project - java

I am currently working on an app using some features that are only accessible in android 9.
I want to distinguish between users that have android 9 and can thereby use these features and users that are on 8.1 or lower for which I have to find an alternative solution.
Based on this information I want to call either the version with the features coming with android 9 or an alternative version that every smartphone can use.
My question now is, is it possible to create a project that contains android 9 "classes" but never get called when the device it is running on is 8.1 or lower.
Or is it not even possible to compile this project for a SDK version below android 9.
I am thankful for every answer.

Just check the Build version like this...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) ...

Related

About new methods and deprecated methods in Android APIs

I'm new to android development.
I'm studying with outdated books, so I'm really confused about new methods.
I'm going to make a simple and light app which can be run even on old devices.
So when I created a new android project, I set "Minimum Required SDK" to API 8, "Target SDK" to API 22 and "Compile With" to API 22.
Does this setting mean the app can work on the devices of API 8, even though I use the methods of API 22?
I'm asking this question due to deprecated methods.
I completed almost a half of my app developing using deprecated ones.
Can I just replace them all with new ones?
Or do I have to prepare multiple codes using different methods to support different platform versions?
(deprecated methods for older versions, and new ones for newer versions?)
Does this setting mean the app can work on the devices of API 8, even though I use the methods of API 22?
Yes. min sdk version is used to restrict the devices running OS with API level < minsdk from using app. Your app won't be shown in the play store for those devices.
I'm asking this question due to deprecated methods.
I haven't faced any issues till now due to depreciated methods. However, I would suggest to use min sdk version as 14 as Google has introduced many UI tweaks and enhancements. If you do some market research, using minsdk version = 14 would cover around 85% android market.
Can I just replace them all with new ones?
Yes, you can.
Or do I have to prepare multiple codes using different methods to support different platform versions?
(deprecated methods for older versions, and new ones for newer versions?)
You can do it also. Older versions do not have support have fragments. Fragments improve user experience drastically for tablets. Similarly, material design for Lollypop devices is awesome. Thee are few examples where you can opt for API level specific implementation. However, it is better to switch for api level >= 14
To clear up your confusion:
Minimum Required SDK
The minimum version of Android you're going to support. To target the largest market share, I recommend API level 14 or above.
Generally, the lower the number, the more Android devices you're targeting.
Target SDK
Basically, all this is saying is what SDK have you tested your app with. If that's KitKat then you can write in the number 19 which is the API number of KitKat, for example. You can find a list of API numbers here. As you test your app with higher and higher versions of Android, you can increase that number.
Setting the Target SDK to be a higher number will mean that you target a lot more devices.
Compile With
Specifies what API number of Android you want to compile your app with.
By default this is the latest version of Android available in the SDK Manager. Should be set high to improve user experience.
Deprecated Methods
As to your question about deprecated methods: You can continue using them. They are deprecated in favour of a newer alternative that may or may not be better in terms of functionality.
Deprecated methods will still work, the deprecated keyword just tells you that there is a newer preferred way to do it. Android is really good at backward compatibility so something compiled for API level 8 should mostly work on newer devices to.
You're going to have to use multiple code branching on version. You can check your system version at runtime like this:
private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
API 8 is really old. Have a look at the version pie chart
You can find more information about this on the Android developers website

App crashing on Droid X

I just built and released an app on TestFlight. However, when I tried to download -> launch the app on my phone it crashes right away.
My DroidX details are:
System Version: 45.621.10.MB810.Verizon.en.US
Android Version: 2.3.4
Kernel Version: 2.6.32.9-g3e80c7a
Build Number: 4.5.1_57_DX9-10
I tested my app on simulator that had the details below:
Device: Nexus 4
Target: Android 4.3 - API Level 18
How can I troubleshoot further to see why my app is crashing? On ADB I don't see options for DroidX in Device and neither do I see option for 2.3.4 under Target.
I'm new and trying to figure out where to go from here to find out why my app is crashing on this phone?
It sounds like you've built the app using an API that isn't available on the Droid X. As you noted above, the X is at Android 2.3.4, and your simulator is at 4.3.
Check here for more information on setting the API in your app's manifest. Android 2.3 is API level 9.
Note, though, that if you downgrade the API your app is using, you won't be able to use features available in newer versions of Android. One of the most noticeable additions to Android since Gingerbread, for example, is the action bar.
If you do want to downgrade, you'll need to download and install the SDK for that API level to use it for development. The easiest way to do that is via the SDK Manager.

Why I still cannot use fragment when using Eclipse(Android)?

First, I've upgraded to API-21 including eclipse android toolkit and SDK.
I want to use the fragment feature and still want to support those 2.x phones
I know that I must use support library - v4.
But the problem is when I create an Android project, it always shows "Navigation Type "Scrollable Tabs + Swipe" requires a minimum SDK version of at least 11, and the current min version is 8".
How could I solve this tricky problem?
======================================
My settings:
Minimum required SDK: API 8
Target SDK: API 17
Compile With: API 17
======================================
Thanks!!
Eclipse's project templates make use of features that require a number of APIs (mostly ActionBar), which are not provided by the support library. While you can use Fragments, with the support library, you don't have the other features associated with the APIs.
You could still implement swipe/scroll tabs by yourself though. However, you will have to create them manually (and not using Eclipse's built-in project templates).
You will need to use android.support.v4.view.PagerTabStrip, android.support.v4.view.ViewPager and android.support.v4.app.Fragment. The documentation is pretty clear and should point you in the right direction.

Develop Android's application for all the versions

i'm developing an android application and i don't know how to make it compatible with all the versions. In eclipse i select only one API level, and in androidManifest i tried to put minSdk and MaxSdk covering all the version, but it crashes on some OS with different version.
How can i make it compatible with all the versions? Can you help me?
Do you really need to support all versions? Check out this chart, which the Android team updates monthly, and tells you what percentage of devices are running which Android versions. As you can see, 97% of devices are on Android 2.1+
I recommend supporting only Android 2.1+ (API level 7) if you can.
Android Platform Versions
I'd say that you'll make life really hard for yourself by attempting to make your application work on antiquated Android versions (and by that I mean 1.5 and 1.6). As Sky mentioned, only target Android 2.1 and above.
Can you please specify what exception is being thrown when you attempt to run the application on a different version of the OS?
Here's my application's definition in the manifest.
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10">
Defining it that way does not guarantee that your application will work on Froyo, Gingerbread and Gingerbread_MR1. Here's an example, I can't use requestSingleUpdate() from the LocationManager class in my application because it was only added in API level 9 (and I intend my application to work in API level 8!).
You need to ensure that you use functionality that is in API level 8 and below. Does that make sense?

Which AVD Target is the right one for a Droid X2?

I am a noob to Android (and Java). I have successfully setup Eclipse and the Android Virtual Device (AVD). I am guessing the AVD's Target is the version of Android to be emulated, but I want to make sure. I am trying to develop something for my Droid X2 phone.
As such...
Which AVD Target is the right one for a Droid X2?
Is there an online list someplace explaining each Target?
...I have Googled both unsuccessfully.
Thank you for the help.
According to motorolas website, the Droid X2 ships with Android 2.2 (api level 8).
I'm not sure if there are any updates rolled out yet, so consider this the lowest version you will get for this device.
So target 2.2. or lower.
But just a general advice: If you want to ship your app to other people, it's usually best to target the broadest audience. So I recommend going for 1.6 as a target, that will still run on your phone. You can start to raise the target version when you notice that you need a certain feature (can be easily done from the "project properties" dialog inside eclipse in 5 seconds). If you don't seem to need any higher api features, you are way more compatible to many more devices this way.
Edit: To the targets. See Android API levels. Clicking on a version takes you to the changelog. Theres info whats new. Also notice that anything below and equal 2.3.3 is a phone os at the moment. Anything equal or above 3.0 is a tablet os.

Categories

Resources