Reputation: 39
Does that mean older Android mobiles won't be able to use an app that has calls that require a minimum API level?
For example, I'm using a calendar.set()
, and it requires API level 24 (current min is 15); and my mobile for testing has Android 4.4.4, API level 19. What can I do? If I use a emulator to test and build the app, am I able to use the app in my mobile when it's done?
Upvotes: 1
Views: 2275
Reputation:
Yes, brother. It will not work at all. Maybe it will cause problem for you.
Upvotes: 0
Reputation: 1803
Yep, the device/emulator's API must be at least the minimum API (minSdkVersion in local build.gradle) as strictly mentioned in Android docs:
minSdkVersion: An integer designating the minimum API Level required for the application to run. The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in this attribute. You should always declare this attribute.
Upvotes: 0
Reputation: 1007124
What happens when a call requires higher API, but my mobile has lower API level (Android app)
You should get warnings in your IDE about the problem, and you will crash at runtime, if you make that call.
I'm using a calendar.set(), and it requires API level 24
There are several variants of set()
on Calendar
, such as this one. All have been around since API Level 1.
Perhaps you have imported the wrong Calendar
class.
What can I do?
If you want to run on API Level 19, you need to try to use classes and methods defined in API Level 19 or before. For optional functionality that you want to use on newer devices, use Build.VERSION.SDK_INT
to see what API level the device is running, and branch around anything that will not work on the older devices.
Upvotes: 2
Reputation: 93658
It throws an exception if that line is run. Any calls to APIs higher than the minimum need to be protected by version checks, and either the feature not exposed on the lower API or done in a different manner.
Upvotes: 0
Reputation: 18725
Yes, your app will crash if it calls a method that is not supported.
You must create a method to check for this condition and programmatically handle this.
This SO shows how to get version: Getting device os version in Android programmatically
You can run the app on an older device, but it will crash when the unsupported code is encountered.
Upvotes: 0