Error but I do not know exactly why

222 views Asked by At

I want to know the technology of battery in Android . I have finished and well done the Javacode with broadcastreceiver . But when I use java class to get battery in Qt , the intent does not run from java code . So I decide to make it run in 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>()); 
        }

}

Both lines make the program halt very badly . I still do not find out

             activity.callObjectMethod("startActivity", "(Landroid/content/Intent;)V", callIntent.object<jobject>());
            //activity.callMethod<void>("startActivity","(Landroid/content/Intent;)V", callIntent.object<jobject>());

Good weekend for Pro ! .

1

There are 1 answers

0
Nam Doan Ha On

I find out the way to solve is to use QtAndroid::androidActivity().callMethod in main and change MyActivity extends QtActivity instead of Activity or else in Android . It is simple and by that way I can get Battery information . That is the bright way to solve . But why my previous code activity.callObjectMethod("startActivity", "(Landroid/content/Intent;)V", callIntent.object()); make program crashed severely is I still do not find out exactly . Thank you .