本文介绍了无法使用QAndroidJniObject调用PowerManager.WakeLock.newWakeLock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图执行这个Java代码:
PowerManager pm =(PowerManager)getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,My Tag);
wl.acquire();使用Qt QAndroidJniObject(我在Android上部署一个Qt应用程序)
$ b
我这样做:
QAndroidJniObject activity = QAndroidJniObject :: callStaticObjectMethod(org / qtproject / qt5 / android / QtNative,activity,()Landroid / app / Activity;);
if(activity.isValid())
{
QAndroidJniObject serviceName = QAndroidJniObject :: getStaticObjectField< jstring>(android / content / Context,POWER_SERVICE);
if(serviceName.isValid())
{
QAndroidJniObject powerMgr = activity.callObjectMethod(getSystemService,(Ljava / lang / String;)Ljava / lang / Object;,serviceName .object< jobject>());
if(powerMgr.isValid())
{
QAndroidJniObject wakeLock = powerMgr.callObjectMethod(newWakeLock,(ILjava / lang / String;)Landroid / os / PowerManager / WakeLock; ,levelAndFlags,tag.object< jstring>());
if(wakeLock.isValid())
wakeLock.callMethod< void>(acquire,()V);
else
assert(false);
}
}
}
从调试器检查: code> levelAndFlags 是正确的(6),标签
是正确的.isValid()返回false。
此行必须有问题:
QAndroidJniObject wakeLock = powerMgr.callObjectMethod(newWakeLock,(ILjava / lang / String;)Landroid / os / PowerManager / WakeLock;,levelAndFlags,tag.object< jstring> ());
但我不知道什么...
解决方案
嵌套类名需要特殊的语法:
/ PowerManager / WakeLock
应为:
Landroid / os / PowerManager $ WakeLock
I'm trying to execute this Java code:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
wl.acquire();
using Qt QAndroidJniObject (I'm deploying a Qt app on Android).
I did that:
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if ( activity.isValid() )
{
QAndroidJniObject serviceName = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Context","POWER_SERVICE");
if ( serviceName.isValid() )
{
QAndroidJniObject powerMgr = activity.callObjectMethod("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;",serviceName.object<jobject>());
if ( powerMgr.isValid() )
{
QAndroidJniObject wakeLock = powerMgr.callObjectMethod("newWakeLock", "(ILjava/lang/String;)Landroid/os/PowerManager/WakeLock;", levelAndFlags,tag.object<jstring>());
if ( wakeLock.isValid() )
wakeLock.callMethod<void>("acquire", "()V");
else
assert( false );
}
}
}
Checked from the debugger: levelAndFlags
is correct (6), tag
is correct ("My Tag"), but wakeLock.isValid()
returns false.
There must be a problem with this line:
QAndroidJniObject wakeLock = powerMgr.callObjectMethod("newWakeLock", "(ILjava/lang/String;)Landroid/os/PowerManager/WakeLock;", levelAndFlags,tag.object<jstring>());
But I can't figure out what...
解决方案
Nested class names requires a special syntax:
Landroid/os/PowerManager/WakeLock
Should be:
Landroid/os/PowerManager$WakeLock
And it works!
这篇关于无法使用QAndroidJniObject调用PowerManager.WakeLock.newWakeLock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!