As the Android version continues to update, the new API is constantly gushing, and sometimes the high-version API is crash in the lower version.
If the minsdkversion setting is too low, the error will be in the build (call requires API level 9);
In order to compile can pass, can add @SuppressLint("NewApi")
or@TargeApi(9)注解。
This is only compiled through, the runtime will still be crash.
The right approach
In order to run without error, you need:
- Determine the runtime version, this method is not called in the low-version system
In order to ensure the integrity of the function, we need to provide the low-version function
Summary: Using a method higher than minSdkVersion
the API level requires:
- If
@TargeApi($API_LEVEL)
the use can be compiled through, then do not use @SuppressLint("NewApi")
;
- Run-time judgment API level; This method is only called in an API level system that is high enough to have this method;
- Ensure functional integrity and ensure that low API versions provide functionality through other methods.
Easy to ignore the API small details, fortunately, IDE development tools, will automatically remind you of.
Android API compatibility on different versions of the system