I'm quite new with Android development, and I wanted to learn a bit about Lint tool and NewApi check. After doing some tests I'm a bit confused though.
After creating new Android application project in IntelliJ IDEA, I added some code to the onCreate method, so it now looks like this:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display d = getWindowManager().getDefaultDisplay();
Point size = new Point();
d.getSize(size); // API level 13
isDestroyed(); // API level 17
NativeActivity nativeActivity = new NativeActivity(); // API level 11
nativeActivity.getContentResolver(); // API level 11
Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); // API level 9
boolean canDisableShutterSound = cameraInfo.canDisableShutterSound; // API level 17
}
In the manifest file I have
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17" />
After compiling the project and running lint from command line:
lint --check NewApi --classpath c:\_dev\TestNewApi\out c:\_dev\TestNewApi
I got the following output:
Scanning TestNewApi: .......
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): android.app.NativeActivity#getContentResolver [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.app.NativeActivity [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Call requires API level 9 (current min is 7): new android.hardware.Camera.CameraInfo [NewApi]
out\production\TestNewApi\com\example\TestNewApi\MyActivity.class: Error: Field requires API level 9 (current min is 7): android.hardware.Camera.CameraInfo#canDisableShutterSound [NewApi]
4 errors, 0 warnings
So no complaints about getSize and isDestroyed methods. And after changing minSdkVersion to 9, the check result is:
Scanning TestNewApi: .......
No issues found.
It looks for me, like only the classes are checked in both cases, and if the class was introduced at or after minSdkVersion, then everything is ok. Is this the expected behavior? Or maybe I'm missing something?