我想知道Android中的电池技术。我已完成并使用broadcastreceiver完成了Javacode。但是当我使用java类在Qt中获取电池时,意图不会从java代码运行。所以我决定让它在Qt中运行。
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
if (activity.isValid())
{
QAndroidJniObject callConstant = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_BATTERY_CHANGED");
QAndroidJniObject callIntent("android/content/Intent", "(Ljava/lang/String;)V", callConstant.object());
QAndroidJniObject param = QAndroidJniObject::fromString("technology" ) ;
mySubstring = callIntent.callObjectMethod("getStringExtra"
,"(Ljava/lang/String;)Ljava/lang/String;"
,param.object()) ;
if(callIntent.isValid())
{
activity.callObjectMethod("startActivity", "(Landroid/content/Intent;)V", callIntent.object<jobject>());
//activity.callMethod<void>("startActivity","(Landroid/content/Intent;)V", callIntent.object<jobject>());
}
}
这两行都使程序停止运行。我还是没找到
activity.callObjectMethod("startActivity", "(Landroid/content/Intent;)V", callIntent.object<jobject>());
//activity.callMethod<void>("startActivity","(Landroid/content/Intent;)V", callIntent.object<jobject>());
亲们度过愉快的周末!
答案 0 :(得分:0)
我发现解决的方法是在main中使用QtAndroid :: androidActivity()。callMethod并更改MyActivity扩展QtActivity而不是Activity,否则在Android中。它很简单,通过这种方式我可以得到电池信息。这是解决问题的明智之举。但是为什么我之前的代码activity.callObjectMethod(“startActivity”,“(Landroid / content / Intent;)V”,callIntent.object());使程序严重崩溃是我仍然没有找到确切的。谢谢。