本文整理汇总了C++中QAndroidJniObject类的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniObject类的具体用法?C++ QAndroidJniObject怎么用?C++ QAndroidJniObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAndroidJniObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getResourceSize
int ScreenValues::getResourceSize(const QString &resource)
{
#ifdef Q_OS_ANDROID
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity",
"()Landroid/app/Activity;");
QAndroidJniObject resources = activity.callObjectMethod("getResources", "()Landroid/content/res/Resources;");
QAndroidJniObject jName = QAndroidJniObject::fromString(resource);
QAndroidJniObject jDefType = QAndroidJniObject::fromString("dimen");
QAndroidJniObject jDefPackage = QAndroidJniObject::fromString("android");
jint identifier = resources.callMethod<jint>("getIdentifier",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
jName.object<jstring>(),
jDefType.object<jstring>(),
jDefPackage.object<jstring>());
jint size = resources.callMethod<jint>("getDimensionPixelSize",
"(I)I", identifier);
return size;
#else
return 0;
#endif
}
示例2: retrieveDpi
int ScreenValues::retrieveDpi()
{
#ifdef Q_OS_ANDROID
QAndroidJniEnvironment env;
env->PushLocalFrame(9);
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity",
"()Landroid/app/Activity;");
QAndroidJniObject resources = activity.callObjectMethod("getResources",
"()Landroid/content/res/Resources;");
QAndroidJniObject displayMetrics = resources.callObjectMethod("getDisplayMetrics",
"()Landroid/util/DisplayMetrics;");
jint densityDpi = displayMetrics.getField<jint>("densityDpi");
int result = (int)densityDpi;
return result;
#else
return QGuiApplication::primaryScreen()->physicalDotsPerInch();
#endif
}
示例3: QVERIFY
void tst_QAndroidJniObject::callStaticBooleanMethod()
{
QAndroidJniEnvironment env;
jclass cls = env->FindClass("java/lang/Boolean");
QVERIFY(cls != 0);
{
QAndroidJniObject parameter = QAndroidJniObject::fromString("true");
QVERIFY(parameter.isValid());
jboolean b = QAndroidJniObject::callStaticMethod<jboolean>(cls,
"parseBoolean",
"(Ljava/lang/String;)Z",
parameter.object<jstring>());
QVERIFY(b);
}
{
QAndroidJniObject parameter = QAndroidJniObject::fromString("false");
QVERIFY(parameter.isValid());
jboolean b = QAndroidJniObject::callStaticMethod<jboolean>(cls,
"parseBoolean",
"(Ljava/lang/String;)Z",
parameter.object<jstring>());
QVERIFY(!b);
}
}
示例4: str
void tst_QAndroidJniObject::compareOperatorTests()
{
QString str("hello!");
QAndroidJniObject stringObject = QAndroidJniObject::fromString(str);
jobject obj = stringObject.object();
jobject jobj = stringObject.object<jobject>();
jstring jsobj = stringObject.object<jstring>();
QVERIFY(obj == stringObject);
QVERIFY(jobj == stringObject);
QVERIFY(stringObject == jobj);
QVERIFY(jsobj == stringObject);
QVERIFY(stringObject == jsobj);
QAndroidJniObject stringObject3 = stringObject.object<jstring>();
QVERIFY(stringObject3 == stringObject);
QAndroidJniObject stringObject2 = QAndroidJniObject::fromString(str);
QVERIFY(stringObject != stringObject2);
jstring jstrobj = 0;
QAndroidJniObject invalidStringObject;
QVERIFY(invalidStringObject == jstrobj);
QVERIFY(jstrobj != stringObject);
QVERIFY(stringObject != jstrobj);
QVERIFY(!invalidStringObject.isValid());
}
示例5: defined
const QString Wpp::getDownloadPath() const
{
QString downloadPath;
#if defined(Q_OS_ANDROID)
//https://qt-project.org/forums/viewthread/35519
QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
downloadPath = mediaPath.toString()+"/Download/";
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
// Handle exception here.
qDebug() << "[ERR]:Android(Extras):getting SD card download path";
env->ExceptionClear();
}
#elif defined(Q_OS_IOS)
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
qDebug() << "[IOS]download paths count:" << paths.size();
downloadPath = paths.first();
#else
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
qDebug() << "[Other OS]download paths count:" << paths.size();
downloadPath = paths.first();
#endif
qDebug() << "downloadPath:" << downloadPath;
return downloadPath;
}
示例6: callActivityMethod_ss
wxString callActivityMethod_ss(const char *method, wxString parm)
{
wxString return_string;
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity", "()Landroid/app/Activity;");
if ( !activity.isValid() ){
qDebug() << "Activity is not valid";
return return_string;
}
// Need a Java environment to decode the resulting string
if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
qDebug() << "GetEnv failed.";
return _T("jenv Error");
}
jstring p = (jenv)->NewStringUTF(parm.c_str());
// Call the desired method
QAndroidJniObject data = activity.callObjectMethod(method, "(Ljava/lang/String;)Ljava/lang/String;", p);
jstring s = data.object<jstring>();
const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
return_string = wxString(ret_string, wxConvUTF8);
return return_string;
}
示例7: qDebug
bool Wpp::vibrate(long milliseconds)
{
#ifdef Q_OS_ANDROID
//http://stackoverflow.com/questions/29644280/how-to-make-phone-vibrate-from-qt-android
/*
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniObject Context__VIBRATOR_SERVICE
= QAndroidJniObject::getStaticObjectField(
"android/content/Context", "VIBRATOR_SERVICE", "Ljava/lang/String;");
qDebug() << "Context__VIBRATOR_SERVICE.isValid()=" << Context__VIBRATOR_SERVICE.isValid();
QAndroidJniObject vibrator = activity.callObjectMethod("getSystemService",
"(Ljava/lang/String;)Ljava/lang/Object;",
Context__VIBRATOR_SERVICE.object<jstring>());
if ( vibrator.isValid() )
{
jlong ms = (jlong)milliseconds;
qDebug() << "vibrator IS valid...:milliseconds=" << ms;
vibrator.callMethod<void>("vibrate", "(J)V", milliseconds);
return true;
}
else
{
qDebug() << "vibrator is NOT valid...";
return false;
}
#endif
}
示例8: qString
void tst_QAndroidJniObject::stringConvertionTest()
{
const QString qString(QLatin1String("Hello, Java"));
QAndroidJniObject jString = QAndroidJniObject::fromString(qString);
QVERIFY(jString.isValid());
QString qStringRet = jString.toString();
QCOMPARE(qString, qStringRet);
}
示例9: keepScreenOn
static void keepScreenOn()
{
QAndroidJniObject activity = QtAndroid::androidActivity();
if (activity.isValid()) {
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
if (window.isValid()) {
const int FLAG_KEEP_SCREEN_ON = 128;
window.callMethod<void>("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
}
}
}
示例10: QLatin1String
void tst_QAndroidJniObject::callObjectMethodTest()
{
const QString qString = QLatin1String("Hello, Java");
QAndroidJniObject jString = QAndroidJniObject::fromString(qString);
const QString qStringRet = jString.callObjectMethod<jstring>("toUpperCase").toString();
QCOMPARE(qString.toUpper(), qStringRet);
QAndroidJniObject subString = jString.callObjectMethod("substring",
"(II)Ljava/lang/String;",
0, 4);
QCOMPARE(subString.toString(), qString.mid(0, 4));
}
示例11: QWidget
MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
{
//LITTLE HACK FOR KEEPING SCREEN ON
QAndroidJniObject activity = QtAndroid::androidActivity();
if (activity.isValid()) {
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
if (window.isValid()) {
window.callMethod<void>("setFlags", "(II)V", 128, 128);
}
}
QPalette pal = palette();
pal.setBrush(QPalette::Background, QBrush(QPixmap(":/background.png")));
setPalette(pal);
ball = new Ball();
scene = new Scene();
scene->addBall(ball);
scene->setSceneRect(-200, -200, 400, 200000);
connect(ball, &Ball::collision, scene, &Scene::gameOver);
view = new View(scene, this);
view->addBall(ball);
view->centerOn(ball);
connect(&scene->timer(), &QTimer::timeout, view, &View::updateBall);
TimeCounter *timeCounter = new TimeCounter(this);
connect(scene, &Scene::passed, timeCounter, &TimeCounter::addTime);
connect(timeCounter, &TimeCounter::timesUp, scene, &Scene::gameOver);
connect(ball, &Ball::collision, timeCounter, &TimeCounter::stop);
PointCounter *pointCounter = new PointCounter(this);
connect(scene, &Scene::passed, pointCounter, &PointCounter::addPoint);
newGameButton = new QPushButton("Restart");
connect(newGameButton, &QPushButton::clicked, ball, &Ball::restart);
connect(newGameButton, &QPushButton::clicked, scene, &Scene::resetScene);
connect(newGameButton, &QPushButton::clicked, timeCounter, &TimeCounter::start);
connect(newGameButton, &QPushButton::clicked, pointCounter, &PointCounter::resetPoints);
QVBoxLayout *layout = new QVBoxLayout();
QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->addWidget(timeCounter);
hLayout->addWidget(pointCounter);
layout->addLayout(hLayout);
layout->addWidget(view);
layout->addWidget(newGameButton);
setLayout(layout);
}
示例12: getAndroidDisplayDimensions
wxSize getAndroidDisplayDimensions( void )
{
wxSize sz_ret = ::wxGetDisplaySize(); // default, probably reasonable, but maybe not accurate
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity", "()Landroid/app/Activity;");
if ( !activity.isValid() ){
qDebug() << "Activity is not valid";
return sz_ret;
}
// Call the desired method
QAndroidJniObject data = activity.callObjectMethod("getDisplayMetrics", "()Ljava/lang/String;");
wxString return_string;
jstring s = data.object<jstring>();
// Need a Java environment to decode the resulting string
if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
qDebug() << "GetEnv failed.";
}
else {
const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
return_string = wxString(ret_string, wxConvUTF8);
}
wxStringTokenizer tk(return_string, _T(";"));
if( tk.HasMoreTokens() ){
wxString token = tk.GetNextToken(); // xdpi
token = tk.GetNextToken(); // density
token = tk.GetNextToken(); // densityDPI
token = tk.GetNextToken();
long a = ::wxGetDisplaySize().x; // default is wxWidgets idea
if(token.ToLong( &a ))
sz_ret.x = a;
token = tk.GetNextToken();
long b = ::wxGetDisplaySize().y;
if(token.ToLong( &b ))
sz_ret.y = b;
}
wxSize sz_wx = ::wxGetDisplaySize(); // default, probably reasonable, but maybe not accurate
qDebug() << sz_wx.x << sz_wx.y << sz_ret.x << sz_ret.y;
return sz_ret;
}
示例13: strdup
const char *system_default_filename(void)
{
/* Replace this when QtCore/QStandardPaths getExternalStorageDirectory landed */
QAndroidJniObject externalStorage = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject externalStorageAbsolute = externalStorage.callObjectMethod("getAbsolutePath", "()Ljava/lang/String;");
QString system_default_filename = externalStorageAbsolute.toString() + "/subsurface.xml";
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
// FIXME: Handle exception here.
env->ExceptionClear();
return strdup("/sdcard/subsurface.xml");
}
return strdup(system_default_filename.toUtf8().data());
}
示例14: instance
void QQmlAndroidImageView::setImageURI(const QUrl &uri)
{
if (m_uri != uri) {
m_uri = uri;
if (isValid()) {
QAndroidJniObject v = instance();
QAndroidJniObject u = getUri();
QtQmlAndroid::callFunction([=]() {
v.callMethod<void>("setImageURI", "(Landroid/net/Uri;)V", u.object());
});
}
emit imageURIChanged();
}
}
示例15: callPaymentRequest
void PaymentAndroid::callPaymentRequest()
{
QAndroidJniObject prIntent = m_class.callObjectMethod("paymentRequest",
"(Landroid/content/Context;)Landroid/content/Intent;",
QtAndroid::androidActivity().object<jobject>());
if(!prIntent.isValid()){
qCritical() << "Wrong intent";
return;
}
QtAndroid::startActivity(prIntent.object<jobject>(), ACTIVITY_REQUEST_CODE_PAYMENT);
// QtAndroid::androidActivity().callObjectMethod("startActivity","(Landroid/content/Intent;)V", prIntent.object<jobject>());
}