Device Orientation Change Callback in Android?

Hi, I want to detect device orientation change in Android.

I wonder if there’s something similar to iOS’s deviceOrientationChanged() callback in Android.

If there’s none, how can I implement Java callback function in ofApp.cpp file?
I would appreciate any advice. Thanks in advance!!

I found this method from OFAndroidVideoGrabber.java

// Currently not used
private class OrientationListener extends OrientationEventListener{
	private int rotation = -1;

	public OrientationListener(Context context) {
		super(context);
	}

	@Override
	public void onOrientationChanged(int orientation) {
		if (orientation == ORIENTATION_UNKNOWN) return;
		try{
			orientation = (orientation + 45) / 90 * 90;
			int newRotation = orientation % 360;

			if (newRotation != rotation) {
				rotation = newRotation;
				Camera.Parameters config = camera.getParameters();
				config.setRotation(rotation);
				camera.setParameters(config);
			}
		} catch(Exception e) {
			
		}
	}
	
}

Maybe this one listens to device’s orientation change ?

I tried many things but still couldn’t figure this out.
Can anyone please give me an advice on how to listen to orientation change on Android?
I would really appreciate it.