Android Camera and App Orientation

Hi @arturo
I am working on an android app using OpenFrameworks.
The camera orientation value is availablle.
But I could not find a way to get the screen orientation value, which changes with device rotation.

Till now I have

Inside OFActivity.java
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
Log.e(“inside configurationChanged” , “Entry”);
OFAndroid.setScreenOrientation(newConfig.orientation);
}

Inside OFApp.cpp
void ofApp::deviceOrientationChanged(ofOrientation newOrientation){
appOrientation = ofOrientationToDegrees(newOrientation);
ofLog() << "The appOrientation angle is " << appOrientation << endl;
}

The logs showed that method inside OFActivity is called. But the cpp method is not called.
Cannot find where the mapping between the java & cpp function is to be specified. Please answer

i believe you don’t need to do anything on the java side. if the application is set in the manifest (i think it’s the default) to change the orientation of the screen if the orientation of the device changes you should get the orientation change and the calback call automatically in c++

Thanks for the reply @arturo

Is deviceOrientationChanged(ofOrientation newOrientation) the only correct function which receives the value from callback. Because I inserted log in both Java and Cpp codes, but couldn’t get any cpp log printed. Believing that the cpp function was never called.

yes that’s the correct function, be sure that your app extends ofxAndroidApp not ofBaseApp and also have you tried without the java code? that might be intercepting the callback so it never arrives to the c++ side

Hi @arturo
The class is derived from ofxAndroidApp only. I have tried it both the ways; with & without java code. Its not working. Below is the cpp event function code.

Inside OFApp.cpp
void ofApp::deviceOrientationChanged(ofOrientation newOrientation){
appOrientation = ofOrientationToDegrees(newOrientation);
ofLog() << "The appOrientation angle is " << appOrientation << endl;
}

which version of OF are you using?

0.9.8 it is

Hi @Akash
Did you manage to listen to the orientation change from ofApp.cpp file?
I also couldn’t print anything from deviceOrientationChanged(ofOrientation newOrientation).
I don’t think it’s even implemented on Android.