本文整理汇总了C++中QAndroidJniObject::callObjectMethod方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniObject::callObjectMethod方法的具体用法?C++ QAndroidJniObject::callObjectMethod怎么用?C++ QAndroidJniObject::callObjectMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniObject
的用法示例。
在下文中一共展示了QAndroidJniObject::callObjectMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateScreenValues
void ScreenValues::updateScreenValues()
{
#ifdef Q_OS_ANDROID
if (m_system.sdkInt() >= 19) {
QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
"activity",
"()Landroid/app/Activity;");
QAndroidJniObject wm = activity.callObjectMethod("getWindowManager", "()Landroid/view/WindowManager;");
QAndroidJniObject display = wm.callObjectMethod("getDefaultDisplay", "()Landroid/view/Display;");
QAndroidJniObject realSize = QAndroidJniObject("android/graphics/Point");
display.callMethod<void>("getRealSize", "(Landroid/graphics/Point;)V", realSize.object());
QAndroidJniObject displayFrame = QAndroidJniObject("android/graphics/Rect");
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
QAndroidJniObject view = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
QAndroidJniObject rootView = view.callObjectMethod("getRootView", "()Landroid/view/View;");
rootView.callMethod<void>("getWindowVisibleDisplayFrame", "(Landroid/graphics/Rect;)V", displayFrame.object());
if (((int) realSize.getField<jint>("y") - (int) displayFrame.callMethod<jint>("height")) - m_statusBarHeight == 0)
setNavBarVisible(false);
else
setNavBarVisible(true);
}
#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: MarbleQuickItem
MarbleMaps::MarbleMaps(QQuickItem *parent) :
MarbleQuickItem(parent),
m_suspended(false)
{
QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());
if (application) {
connect(application, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
this, SLOT(handleApplicationStateChange(Qt::ApplicationState)));
}
#ifdef Q_OS_ANDROID
// If a file is passed, open it. Possible file types are registered in package/AndroidManifest.xml
QAndroidJniObject const activity = QtAndroid::androidActivity();
if (activity.isValid()) {
QAndroidJniObject const intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
if (intent.isValid()) {
QAndroidJniObject const data = intent.callObjectMethod("getData", "()Landroid/net/Uri;");
if (data.isValid()) {
QAndroidJniObject const path = data.callObjectMethod("getPath", "()Ljava/lang/String;");
if (path.isValid()) {
model()->addGeoDataFile(path.toString());
connect( model()->fileManager(), SIGNAL(centeredDocument(GeoDataLatLonBox)), this, SLOT(centerOn(GeoDataLatLonBox)) );
}
}
}
}
#endif
}
示例4: 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;
}
示例5: getDownloadPath
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: vibrate
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
}
示例7: 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
}
示例8: createAlbumPath
QString Wpp::createAlbumPath(const QString& albumName)
{
QString parentPath;
#if defined(Q_OS_ANDROID)
QAndroidJniObject Environment__MEDIA_MOUNTED = QAndroidJniObject::getStaticObjectField(
"android/os/Environment", "MEDIA_MOUNTED", "Ljava/lang/String;");
qDebug() << "Environment__MEDIA_MOUNTED:isValid:" << Environment__MEDIA_MOUNTED.isValid() << ":toString:" << Environment__MEDIA_MOUNTED.toString();
QString Environment__MEDIA_MOUNTED_STRING = Environment__MEDIA_MOUNTED.toString();
QAndroidJniObject mediaState = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageState", "()Ljava/lang/String;");
QString mediaStateString = mediaState.toString();
qDebug() <<"mediaStateString:"<< mediaStateString;
if(mediaStateString != Environment__MEDIA_MOUNTED_STRING )
{
qDebug() << "No SD Card...";
return QString();
}
//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;" );
parentPath = mediaPath.toString();
QAndroidJniEnvironment env;
if (env->ExceptionCheck()) {
// Handle exception here.
qDebug() << "[ERR]:Android(Extras):getting SD card path";
env->ExceptionClear();
}
#elif defined(Q_OS_IOS)
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
qDebug() << "[IOS]album parent paths count:" << paths.size();
parentPath = paths.first();
#else
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
qDebug() << "[Other OS]album parent paths count:" << paths.size();
parentPath = paths.first();
#endif
QDir dir(parentPath);
qDebug() << __FUNCTION__ << ":dir=" << dir.dirName();
QString userAlbumPath = parentPath.append("/").append(albumName);;
QDir userAlbumDir = userAlbumPath;
if( !userAlbumDir.exists() )
{
qDebug() << albumName << ":not exists, create it";
dir.mkpath( albumName );
}
else
{
qDebug() << albumName << ":exists";
}
return userAlbumPath;
}
示例9: getLocalPathFromUri
QString getLocalPathFromUri(const QAndroidJniObject& uri) {
// uri: Landroid/net/Uri;
// [url](http://stackoverflow.com/questions/34163437/qt-and-android-gallery-mediastore-using-qandroidjniobject)
QAndroidJniObject dadosAndroid
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns",
"DATA",
"Ljava/lang/String;");
QAndroidJniEnvironment env;
jobjectArray projecao
= (jobjectArray)env->NewObjectArray(1,
env->FindClass("java/lang/String"),
NULL);
jobject projacaoDadosAndroid
= env->NewStringUTF(dadosAndroid.toString().toStdString().c_str());
env->SetObjectArrayElement(projecao, 0, projacaoDadosAndroid);
QAndroidJniObject contentResolver
= QtAndroid::androidActivity()
.callObjectMethod("getContentResolver",
"()Landroid/content/ContentResolver;");
QAndroidJniObject cursor
= contentResolver.callObjectMethod("query",
"(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;",
uri.object<jobject>(), projecao, NULL, NULL, NULL);
jint columnIndex = cursor.callMethod<jint>("getColumnIndex",
"(Ljava/lang/String;)I",
dadosAndroid.object<jstring>());
cursor.callMethod<jboolean>("moveToFirst", "()Z");
QAndroidJniObject resultado
= cursor.callObjectMethod("getString",
"(I)Ljava/lang/String;",
columnIndex);
QString imagemCaminho = "file://" + resultado.toString();
return imagemCaminho;
}
示例10: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
QQmlContext *context = engine.rootContext();
HousetrailModel aHouseTrailImages;
Dialog dialog(&aHouseTrailImages);
QSortFilterProxyModel detailsProxyModel;
detailsProxyModel.setFilterRole(HousetrailModel::HousetrailRoles::CategoryRole);
// MyViewModel::MyViewModel_Roles::MyViewModel_Roles_Details);
//detailsProxyModel->setFilterRegExp( "^\\S+$" );
detailsProxyModel.setSourceModel(&aHouseTrailImages);
qreal dpi;
#if defined(Q_OS_ANDROID)
QAndroidJniObject qtActivity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
QAndroidJniObject resources = qtActivity.callObjectMethod("getResources","()Landroid/content/res/Resources;");
QAndroidJniObject displayMetrics = resources.callObjectMethod("getDisplayMetrics","()Landroid/util/DisplayMetrics;");
int density = displayMetrics.getField<int>("densityDpi");
dpi = density;
// qreal dpiRef = 132; //reference device dpi (ipad);
// if(densitydpi > 0 && dpiRef > 0)
// density = densitydpi / dpiRef;
#else
dpi = app.primaryScreen()->physicalDotsPerInch() * app.devicePixelRatio();
#endif
// channel.registerObject(QStringLiteral("dialog"), &dialog);
context->setContextProperty(QStringLiteral("dialog"), &dialog);
context->setContextProperty(QStringLiteral("houseTrailModel"), &aHouseTrailImages);
context->setContextProperty(QStringLiteral("filteredTrailModel"), &detailsProxyModel);
context->setContextProperty(QStringLiteral("screenDpi"), dpi);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
示例11: handleActivityResult
void NativeMap::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data)
{
int LOCATE_EVENT_VENUE = 1;
jint Activity__RESULT_OK = QAndroidJniObject::getStaticField<jint>(
"android.app.Activity", "RESULT_OK");
if ( receiverRequestCode == LOCATE_EVENT_VENUE
&& resultCode == Activity__RESULT_OK )
{
QAndroidJniObject addressName = QAndroidJniObject::fromString(QString("addressName"));
QAndroidJniObject lat = QAndroidJniObject::fromString(QString("latitude"));
QAndroidJniObject lon = QAndroidJniObject::fromString(QString("longitude"));
QAndroidJniObject extras = data.callObjectMethod("getExtras","()Landroid/os/Bundle;");
qDebug() << __FUNCTION__ << "extras.isValid()=" << extras.isValid();
QAndroidJniObject addressNameObj = extras.callObjectMethod("getString","(Ljava/lang/String;)Ljava/lang/String;",
addressName.object<jobject>());
qDebug() << __FUNCTION__ << "addressNameObj.isValid()=" << addressNameObj.isValid();
QAndroidJniObject latitudeObj = extras.callObjectMethod("getString","(Ljava/lang/String;)Ljava/lang/String;",
lat.object<jobject>());
qDebug() << __FUNCTION__ << "latitudeObj.isValid()=" << latitudeObj.isValid();
QAndroidJniObject longitudeObj = extras.callObjectMethod("getString","(Ljava/lang/String;)Ljava/lang/String;",
lon.object<jobject>());
qDebug() << __FUNCTION__ << "longitudeObj.isValid()=" << longitudeObj.isValid();
qDebug() << __FUNCTION__ << "address=" << addressNameObj.toString();
//this->setVenue(addressNameObj.toString());
emit this->locationSelected(
longitudeObj.toString().toDouble(),
latitudeObj.toString().toDouble(),
addressNameObj.toString());
// double lond = (double)longitudeObj.callMethod<jdouble>("doubleValue", "()D");
// double latd = (double)latitudeObj.callMethod<jdouble>("doubleValue", "()D");
qDebug() << __FUNCTION__ << "latd.isValid()=" << latitudeObj.toString();
qDebug() << __FUNCTION__ << "lond.isValid()=" << longitudeObj.toString();
//this->setLatitude(latitudeObj.toString().toDouble());
//this->setLongitude(longitudeObj.toString().toDouble());
}
}
示例12: updateDPI
void UnitsAttached::updateDPI()
{
if (m_screen == nullptr) {
m_dpi = DEFAULT_DPI;
return;
}
#if defined(Q_OS_IOS)
// iOS integration of scaling (retina, non-retina, 4K) does itself.
m_dpi = m_screen->physicalDotsPerInch();
#elif defined(Q_OS_ANDROID)
// https://bugreports.qt-project.org/browse/QTBUG-35701
// recalculate dpi for Android
QAndroidJniEnvironment env;
QAndroidJniObject activity = QtAndroid::androidActivity();
QAndroidJniObject resources =
activity.callObjectMethod("getResources", "()Landroid/content/res/Resources;");
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
m_dpi = DEFAULT_DPI;
return;
}
QAndroidJniObject displayMetrics =
resources.callObjectMethod("getDisplayMetrics", "()Landroid/util/DisplayMetrics;");
if (env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
m_dpi = DEFAULT_DPI;
return;
}
m_dpi = displayMetrics.getField<int>("densityDpi");
m_multiplier = displayMetrics.getField<float>("density");
#else
// standard dpi
m_dpi = m_screen->logicalDotsPerInch() * m_screen->devicePixelRatio();
#endif
}
示例13: 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);
}
}
}
示例14: callObjectMethodTest
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));
}
示例15: 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);
}