QmlAndroid旋转屏幕

android的API setRequestedOrientation可以旋转屏幕

QmlAndroidOrientation::QmlAndroidOrientation(QObject *parent) : QObject(parent)
{
activity = androidActivity();
}

QString QmlAndroidOrientation::setOrientationPortrait()
{
activity.callMethod("setRequestedOrientation", "(I)V", 1);
if(env->ExceptionCheck())
{
qDebug() << "exception occured";
env->ExceptionClear();
}
return(getOrientation());
}

QString QmlAndroidOrientation::setOrientationLandscape()
{
activity.callMethod("setRequestedOrientation", "(I)V", 0);
if(env->ExceptionCheck())
{
qDebug() << "exception occured";
env->ExceptionClear();
}
return(getOrientation());
}

QString QmlAndroidOrientation::getOrientation()
{
jint orient = activity.callMethod("getRequestedOrientation");
if(env->ExceptionCheck())
{
qDebug() << "exception occured";
env->ExceptionClear();
}

return ((orient == 0) ? QStringLiteral("横屏") : QStringLiteral("竖屏"));

}

image.png

需要完整代码请访问QtAndroidExamples

你可能感兴趣的:(QmlAndroid旋转屏幕)