本文整理汇总了C++中QAndroidJniEnvironment::NewStringUTF方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::NewStringUTF方法的具体用法?C++ QAndroidJniEnvironment::NewStringUTF怎么用?C++ QAndroidJniEnvironment::NewStringUTF使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAndroidJniEnvironment
的用法示例。
在下文中一共展示了QAndroidJniEnvironment::NewStringUTF方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createHashMap
static jobject createHashMap(const QVariantMap &data) {
QAndroidJniEnvironment env;
jclass mapClass = env->FindClass("java/util/HashMap");
if (mapClass == NULL) {
qWarning() << "Failed to find class" << "java/util/HashMap";
return NULL;
}
jclass integerClass = env->FindClass("java/lang/Integer");
jmethodID integerConstructor = env->GetMethodID(integerClass, "<init>", "(I)V");
jclass booleanClass = env->FindClass("java/lang/Boolean");
jmethodID booleanConstructor = env->GetMethodID(booleanClass,"<init>","(Z)V");
jsize map_len = data.size();
jmethodID init = env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hashMap = env->NewObject( mapClass, init, map_len);
jmethodID put = env->GetMethodID( mapClass, "put",
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
QMapIterator<QString, QVariant> iter(data);
while (iter.hasNext()) {
iter.next();
// qDebug() << iter.key() << iter.value();
QString key = iter.key();
jstring jkey = env->NewStringUTF(key.toLocal8Bit().data());
QVariant v = iter.value();
if (v.type() == QVariant::String) {
QString str = v.toString();
jstring vString = env->NewStringUTF(str.toLocal8Bit().data());
env->CallObjectMethod(hashMap,put,jkey,vString);
} else if (v.type() == QVariant::Int) {
jobject integer = env->NewObject(integerClass,integerConstructor,v.toInt());
env->CallObjectMethod(hashMap,put,jkey,integer);
} else if (v.type() == QVariant::Bool) {
jobject boolean = env->NewObject(booleanClass,booleanConstructor,v.toBool());
env->CallObjectMethod(hashMap,put,jkey,boolean);
} else {
qWarning() << "QASystemDispatcher: Non-supported data type - " << v.type();
}
}
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
env->ExceptionClear();
}
return hashMap;
}
示例2: dispatch
void QASystemDispatcher::dispatch(QString name, QVariantMap message)
{
#ifdef Q_OS_ANDROID
QAndroidJniEnvironment env;
jstring jName = env->NewStringUTF(name.toLocal8Bit().data());
jobject jData = createHashMap(message);
QAndroidJniObject::callStaticMethod<jboolean>(JCLASS_Name, "dispatch",
DISPATCH_SIGNATURE,
jName,jData);
#endif
}
示例3: 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;
}
示例4: handleActivityResult
//.........这里部分代码省略.........
QString path(rawString);
qDebug() << "path[]=" << path;
paths.append(path);
env->ReleaseStringUTFChars(string, rawString);
}
emit this->accepted(paths);
}
else
{
QAndroidJniEnvironment env;
QAndroidJniObject uri = data.callObjectMethod("getData","()Landroid/net/Uri;");
qDebug() << __FUNCTION__ << "uri.isValid()=" << uri.isValid();
qDebug() << __FUNCTION__ << "uri=" << uri.toString();
/*
url is like: "content://media/external/images/media/87332"
for KitKat(android 4.4), uri is like: "content://com.android.providers.media.documents/document/image:3951"
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniObject contentResolver = activity.callObjectMethod("getContentResolver","()Landroid/content/ContentResolver;");
qDebug() << __FUNCTION__ << "contentResolver.isValid()=" << contentResolver.isValid();
/*if ( receiverRequestCode == PICK_FROM_FILE_KITKAT )
{
jint Intent__FLAG_GRANT_READ_URI_PERMISSION = QAndroidJniObject::getStaticField<jint>(
"android.content.Intent", "FLAG_GRANT_READ_URI_PERMISSION");
jint Intent__FLAG_GRANT_WRITE_URI_PERMISSION = QAndroidJniObject::getStaticField<jint>(
"android.content.Intent", "FLAG_GRANT_WRITE_URI_PERMISSION");
jint takeFlags = data.callMethod<jint>("getFlags","()I");
takeFlags = takeFlags & ( Intent__FLAG_GRANT_READ_URI_PERMISSION | Intent__FLAG_GRANT_WRITE_URI_PERMISSION );
contentResolver.callMethod<void>("takePersistableUriPermission","(Landroid/net/Uri;I)V",
uri.object<jobject>(), takeFlags);
}*/
/*
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
*/
QAndroidJniObject MediaStore_Images_Media_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");
//"android/provider/MediaStore$Images$Media", "DATA", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_DATA.isValid()=" << MediaStore_Images_Media_DATA.isValid();
QAndroidJniObject nullObj;
jstring emptyJString = env->NewStringUTF("");
jobjectArray projection = (jobjectArray)env->NewObjectArray(
1,
env->FindClass("java/lang/String"),
emptyJString
);
jobject projection0 = env->NewStringUTF( MediaStore_Images_Media_DATA.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 0, projection0 );
// Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
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>(), projection, nullObj.object<jstring>(), nullObj.object<jobjectArray>(), nullObj.object<jstring>());
qDebug() << __FUNCTION__ << "cursor.isValid()=" << cursor.isValid();
//int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
jint column_index = cursor.callMethod<jint>(
"getColumnIndexOrThrow","(Ljava/lang/String;)I", MediaStore_Images_Media_DATA.object<jstring>());
qDebug() << "column_index=" << column_index;
//cursor.moveToFirst();
cursor.callMethod<jboolean>("moveToFirst");
// String path = cursor.getString(column_index);
QAndroidJniObject path = cursor.callObjectMethod(
"getString",
"(I)Ljava/lang/String;", column_index );
qDebug() << __FUNCTION__ << "path.isValid()=" << path.isValid();
QString filePath = path.toString();
qDebug() << "filePath=" << filePath;
//cursor.close();
cursor.callMethod<jboolean>("close");
env->DeleteLocalRef(emptyJString);
env->DeleteLocalRef(projection);
env->DeleteLocalRef(projection0);
QStringList paths;
paths.append(filePath);
emit this->accepted(paths);
//m_imagePath = filePath;
//emit this->imagePathChanged();
}
}
}
示例5: managedQuery
QList<QObject *> Gallery::fetchAll()
{
#ifdef Q_OS_ANDROID
//ref(android): http://stackoverflow.com/questions/4195660/get-list-of-photo-galleries-on-android
//ref(thumbnail): http://stackoverflow.com/questions/5013176/displaying-photo-thumbnails-on-map
/*
// which image properties are we querying
String[] projection = new String[]{
MediaStore.Images.Media._ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN
};
*/
QAndroidJniObject MediaStore_Images_Media__ID
= QAndroidJniObject::getStaticObjectField(
"android/provider/BaseColumns", "_ID", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media__ID.isValid()=" << MediaStore_Images_Media__ID.isValid();
QAndroidJniObject MediaStore_Images_Media_BUCKET_ID
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$ImageColumns", "BUCKET_ID", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_BUCKET_ID.isValid()=" << MediaStore_Images_Media_BUCKET_ID.isValid();
QAndroidJniObject MediaStore_Images_Media_BUCKET_DISPLAY_NAME
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$ImageColumns", "BUCKET_DISPLAY_NAME", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_BUCKET_DISPLAY_NAME.isValid()=" << MediaStore_Images_Media_BUCKET_DISPLAY_NAME.isValid();
QAndroidJniObject MediaStore_Images_Media_DATE_TAKEN
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$ImageColumns", "DATE_TAKEN", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_DATE_TAKEN.isValid()=" << MediaStore_Images_Media_DATE_TAKEN.isValid();
QAndroidJniObject MediaStore_MediaColumns_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");
qDebug() << "MediaStore_MediaColumns_DATA.isValid()=" << MediaStore_MediaColumns_DATA.isValid();
QAndroidJniObject MediaStore_MediaColumns_WIDTH
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "WIDTH", "Ljava/lang/String;");
qDebug() << "MediaStore_MediaColumns_WIDTH.isValid()=" << MediaStore_MediaColumns_WIDTH.isValid();
QAndroidJniObject MediaStore_MediaColumns_HEIGHT
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "HEIGHT", "Ljava/lang/String;");
qDebug() << "MediaStore_MediaColumns_HEIGHT.isValid()=" << MediaStore_MediaColumns_HEIGHT.isValid();
QAndroidJniObject MediaStore_Images_ImageColumns_MINI_THUMB_MAGIC
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$ImageColumns", "MINI_THUMB_MAGIC", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_ImageColumns_MINI_THUMB_MAGIC.isValid()=" << MediaStore_Images_ImageColumns_MINI_THUMB_MAGIC.isValid();
jint MediaStore_Images_Thumbnails_MICRO_KIND = QAndroidJniObject::getStaticField<jint>(
"android/provider/MediaStore$Images$Thumbnails", "MICRO_KIND");
qDebug() << "MediaStore_Images_Thumbnails_MICRO_KIND=" << MediaStore_Images_Thumbnails_MICRO_KIND;
QAndroidJniObject MediaStore_Images_Thumbnails_IMAGE_ID
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$Thumbnails", "IMAGE_ID", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Thumbnails_IMAGE_ID.isValid()=" << MediaStore_Images_Thumbnails_IMAGE_ID.isValid();
QAndroidJniObject MediaStore_Images_ImageColumns_ORIENTATION
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$Images$ImageColumns", "ORIENTATION", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_ImageColumns_ORIENTATION.isValid()=" << MediaStore_Images_ImageColumns_ORIENTATION.isValid();
QAndroidJniEnvironment env;
jstring emptyJString = env->NewStringUTF("");
jobjectArray projection = (jobjectArray)env->NewObjectArray(
9,
env->FindClass("java/lang/String"),
emptyJString
);
jobject projection0 = env->NewStringUTF( MediaStore_Images_Media__ID.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 0, projection0 );
jobject projection1 = env->NewStringUTF( MediaStore_Images_Media_BUCKET_ID.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 1, projection1 );
jobject projection2 = env->NewStringUTF( MediaStore_Images_Media_BUCKET_DISPLAY_NAME.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 2, projection2 );
jobject projection3 = env->NewStringUTF( MediaStore_Images_Media_DATE_TAKEN.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 3, projection3 );
jobject projection4 = env->NewStringUTF( MediaStore_MediaColumns_DATA.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 4, projection4 );
jobject projection5 = env->NewStringUTF( MediaStore_MediaColumns_WIDTH.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 5, projection5 );
jobject projection6 = env->NewStringUTF( MediaStore_MediaColumns_HEIGHT.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 6, projection6 );
jobject projection7 = env->NewStringUTF( MediaStore_Images_ImageColumns_MINI_THUMB_MAGIC.toString().toStdString().c_str() );
env->SetObjectArrayElement(
//.........这里部分代码省略.........
示例6: handleActivityResult
void Gallery::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data)
{
int PICK_FROM_FILE = 1;
int SHOOT_PHOTO = 2;
jint Activity__RESULT_OK = QAndroidJniObject::getStaticField<jint>(
"android.app.Activity", "RESULT_OK");
if ( receiverRequestCode == PICK_FROM_FILE && resultCode == Activity__RESULT_OK )
{
QAndroidJniEnvironment env;
QAndroidJniObject uri = data.callObjectMethod("getData","()Landroid/net/Uri;");
qDebug() << __FUNCTION__ << "uri.isValid()=" << uri.isValid();
qDebug() << __FUNCTION__ << "uri=" << uri.toString();
/*
url is like: "content://media/external/images/media/87332"
*/
QAndroidJniObject activity = QtAndroid::androidActivity();
qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();
QAndroidJniObject contentResolver = activity.callObjectMethod("getContentResolver","()Landroid/content/ContentResolver;");
qDebug() << __FUNCTION__ << "contentResolver.isValid()=" << contentResolver.isValid();
/*
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
*/
QAndroidJniObject MediaStore_Images_Media_DATA
= QAndroidJniObject::getStaticObjectField(
"android/provider/MediaStore$MediaColumns", "DATA", "Ljava/lang/String;");
qDebug() << "MediaStore_Images_Media_DATA.isValid()=" << MediaStore_Images_Media_DATA.isValid();
QAndroidJniObject nullObj;
jstring emptyJString = env->NewStringUTF("");
jobjectArray projection = (jobjectArray)env->NewObjectArray(
1,
env->FindClass("java/lang/String"),
emptyJString
);
jobject projection0 = env->NewStringUTF( MediaStore_Images_Media_DATA.toString().toStdString().c_str() );
env->SetObjectArrayElement(
projection, 0, projection0 );
// Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
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>(), projection, nullObj.object<jstring>(), nullObj.object<jobjectArray>(), nullObj.object<jstring>());
qDebug() << __FUNCTION__ << "cursor.isValid()=" << cursor.isValid();
//int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
jint column_index = cursor.callMethod<jint>(
"getColumnIndexOrThrow","(Ljava/lang/String;)I", MediaStore_Images_Media_DATA.object<jstring>());
qDebug() << "column_index=" << column_index;
//cursor.moveToFirst();
cursor.callMethod<jboolean>("moveToFirst");
// String path = cursor.getString(column_index);
QAndroidJniObject path = cursor.callObjectMethod(
"getString",
"(I)Ljava/lang/String;", column_index );
qDebug() << __FUNCTION__ << "path.isValid()=" << path.isValid();
QString filePath = path.toString();
//cursor.close();
cursor.callMethod<jboolean>("close");
env->DeleteLocalRef(emptyJString);
env->DeleteLocalRef(projection);
env->DeleteLocalRef(projection0);
/*
QAndroidJniObject inputStream = contentResolver.callObjectMethod(
"openInputStream","(Landroid/net/Uri;)Ljava/io/InputStream;", uri.object<jobject>());
qDebug() << __FUNCTION__ << "inputStream.isValid()=" << inputStream.isValid();
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
QDir dir( paths.first() );
QDir parentDir( dir.filePath("..") );
qDebug() << "parent path: " << parentDir.absolutePath();
if ( !dir.exists() )
{
qDebug() << "dir not exist, make it:" << dir;
qDebug() << "dir.name: " << dir.dirName();
qDebug() << "new make dir returns: " << parentDir.mkpath( dir.dirName() );
//qDebug() << "make dir returns: " << dir.mkdir(".");
}
QString pickFile = paths.first().append("/").append("PickFile");
QAndroidJniEnvironment env;
jbyteArray byteArray = env->NewByteArray(1024);
jint fileSize = inputStream.callMethod<jint>(
"available","()I");
qDebug() << "fileSize=" << fileSize;
QFile file( pickFile );
//.........这里部分代码省略.........