NewApi error : Finds API accesses to APIs that are not supported in all targeted API versions


❗️ NewApi error: Finds API accesses to APIs that are not supported in all targeted API versions

The above lint error message is displayed for your Android project when you use a method form an API that is not supported by all the Android APIs levels that you target.

Solution

You can either change the minSdkVersion and targetSdkVersion in your AndroidManifest.xml for unsupported APIs.

If you want to support all versions that you have stated in AndroidManifest then you need to use "Conditional execution" i.e. add conditions in your code based on the API level.

if (android.os.Build.VERSION.RELEASE.startsWith("2.")  {
  //Some code
}
else if (android.os.Build.VERSION.RELEASE.startsWith("3.")  {
  //Some code
}
 else {
  //Some code
 }

You can also use @TargetApi annotation to set the SDK level to apply to your code, example

@TargetApi(18)
public class DoSomething {
   //You Code
}

The above code will consider API level 18 rather than what is being defined in the AndroidManifest.xml file. But not that you cannot use @TargetApi for a method.

✌️ You can use tools:targetApi="" in the Android XML files to support certain API levels.






Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on Code2care.org and support us pay our bills.

Thanks,
Cod2care - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities. Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, Tips-n-tricks, How Tos, Blogs, Articles, etc. on various platforms like Windows, Mac, Linux, Mobile platforms, etc. Technologies/Languages like Java, Objective-C, PHP, .Net, Android, SharePoint, jQuery, HTML, CSS, etc.