当前位置: 首页>>代码示例>>C++>>正文


C++ QAndroidJniEnvironment::GetObjectArrayElement方法代码示例

本文整理汇总了C++中QAndroidJniEnvironment::GetObjectArrayElement方法的典型用法代码示例。如果您正苦于以下问题:C++ QAndroidJniEnvironment::GetObjectArrayElement方法的具体用法?C++ QAndroidJniEnvironment::GetObjectArrayElement怎么用?C++ QAndroidJniEnvironment::GetObjectArrayElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QAndroidJniEnvironment的用法示例。


在下文中一共展示了QAndroidJniEnvironment::GetObjectArrayElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: availablePortsByFiltersOfDevices

QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok)
{
    QList<QSerialPortInfo> serialPortInfoList;

    //__android_log_print(ANDROID_LOG_INFO, V_TAG, "Collecting device list");
    QAndroidJniObject resultL = QAndroidJniObject::callStaticObjectMethod(
        V_jniClassName,
        "availableDevicesInfo",
        "()[Ljava/lang/String;");
    
    if (!resultL.isValid()) {
        __android_log_print(ANDROID_LOG_ERROR, V_TAG, "Error from availableDevicesInfo");
        ok = false;
        return serialPortInfoList;
    }

    QAndroidJniEnvironment envL;
    jobjectArray objArrayL = resultL.object<jobjectArray>();
    int countL = envL->GetArrayLength(objArrayL);

    for (int iL = 0; iL < countL; iL++)
    {
        QSerialPortInfoPrivate priv;
        jstring stringL = (jstring)(envL->GetObjectArrayElement(objArrayL, iL));
        const char *rawStringL = envL->GetStringUTFChars(stringL, 0);
        //__android_log_print(ANDROID_LOG_INFO, V_TAG, "Adding device: %s", rawStringL);
        QStringList strListL = QString::fromUtf8(rawStringL).split(QStringLiteral(":"));
        envL->ReleaseStringUTFChars(stringL, rawStringL);

        priv.portName               = strListL[0];
        priv.device                 = strListL[0];
        priv.manufacturer           = strListL[1];
        priv.productIdentifier      = strListL[2].toInt();
        priv.hasProductIdentifier   = (priv.productIdentifier != 0) ? true: false;
        priv.vendorIdentifier       = strListL[3].toInt();
        priv.hasVendorIdentifier    = (priv.vendorIdentifier  != 0) ? true: false;

        serialPortInfoList.append(priv);
    }

    return serialPortInfoList;
}
开发者ID:Aperture-Laboratories,项目名称:qgroundcontrol,代码行数:42,代码来源:qserialportinfo_android.cpp

示例2: test

void Wpp::test()
{
#ifdef Q_OS_ANDROID
	/*myUsbManager = (UsbManager) getSystemService(USB_SERVICE);
			HashMap<String, UsbDevice> deviceList = myUsbManager.getDeviceList();

			if (!deviceList.isEmpty())
			{
				for (UsbDevice device : deviceList.values())
				{
					// 枚举设备
					if (device.getVendorId() == VendorID && device.getProductId() == ProductID)
					{
						myUsbDevice = device;
					}
				}
			}
	*/
	int VendorID = 0;
	int ProductID = 0;
	QAndroidJniObject myUsbDevice;

	QAndroidJniObject activity = QtAndroid::androidActivity();
	qDebug() << __FUNCTION__ << "activity.isValid()=" << activity.isValid();

	QAndroidJniObject Context__USB_SERVICE = QAndroidJniObject::getStaticObjectField(
				"android/content/Context", "USB_SERVICE", "Ljava/lang/String;");
	qDebug() << __FUNCTION__ << "Context__USB_SERVICE.isValid()=" << Context__USB_SERVICE.isValid();

	//myUsbManager = (UsbManager) getSystemService(USB_SERVICE);
	QAndroidJniObject myUsbManager = activity.callObjectMethod(
				"getSystemService","(Ljava/lang/String;)Ljava/lang/Object;",
				Context__USB_SERVICE.object<jobject>() );
	qDebug() << __FUNCTION__ << "myUsbManager.isValid()=" << myUsbManager.isValid();

	//HashMap<String, UsbDevice> deviceList = myUsbManager.getDeviceList();
	QAndroidJniObject deviceList = myUsbManager.callObjectMethod(
				"getDeviceList","()Ljava/util/HashMap;");
	qDebug() << __FUNCTION__ << "deviceList.isValid()=" << deviceList.isValid();


	jboolean isEmpty = true;
	isEmpty = deviceList.callMethod<jboolean>("isEmpty");
	if ( !isEmpty )
	{
		//HashMap - Collection<V> 	values()
		QAndroidJniObject values = deviceList.callObjectMethod(
					"values","()Ljava/util/Collection;");
		qDebug() << __FUNCTION__ << "values.isValid()=" << values.isValid();

		//Collection - abstract Object[] 	toArray()
		QAndroidJniObject valuesArrayObj = values.callObjectMethod(
					"toArray","()[Ljava/lang/Object;");
		qDebug() << __FUNCTION__ << "valuesArrayObj.isValid()=" << valuesArrayObj.isValid();

		QAndroidJniEnvironment env;

		jobjectArray valuesArray = valuesArrayObj.object<jobjectArray>();
		const int valuesCount = env->GetArrayLength(valuesArray);
		qDebug() << __FUNCTION__ << ":valuesArray=" << (void*)valuesArray;
		qDebug() << __FUNCTION__ << ":valuesCount=" << valuesCount;

		for ( int i = 0 ; i < valuesCount ; i++ )
		{
			jobject value = env->GetObjectArrayElement(valuesArray, i);

			QAndroidJniObject device(value);

			//device.getVendorId()
			jint vendorId = deviceList.callMethod<jint>("getVendorId","()I");
			qDebug() << "i=" << i << ":vendorId=" << vendorId;
			//device.getProductId()
			jint productId = deviceList.callMethod<jint>("getProductId","()I");
			qDebug() << "i=" << i << ":productId=" << productId;
			if ( productId == ProductID && vendorId == VendorID )
			{
				myUsbDevice = device;
			}
		}

	}

#endif
}
开发者ID:AndrewDesign,项目名称:wpp-qt,代码行数:84,代码来源:Wpp.cpp

示例3: handleActivityResult

void ImagePicker::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject & data)
{
	qDebug() << __FUNCTION__;
	int PICK_FROM_FILE = 2;
	int PICK_FROM_FILE_KITKAT = 3;
	jint Activity__RESULT_OK = QAndroidJniObject::getStaticField<jint>(
				"android/app/Activity", "RESULT_OK");
	qDebug() << __FUNCTION__ <<":receiverRequestCode=" << receiverRequestCode
								<< ",resultCode=" << resultCode
								<< ",Activity__RESULT_OK=" << Activity__RESULT_OK;

	if ( ( receiverRequestCode == PICK_FROM_FILE || receiverRequestCode == PICK_FROM_FILE_KITKAT
		   || receiverRequestCode == 200
		   || receiverRequestCode == 9000 )
		 && resultCode == Activity__RESULT_OK )
	{
		if ( receiverRequestCode == 200 )
		{
			QAndroidJniEnvironment env;

			QAndroidJniObject pathsJavaObj = data.callObjectMethod("getStringArrayExtra","(Ljava/lang/String;)[Ljava/lang/String;");
			qDebug() << __FUNCTION__ << "pathsJavaObj.isValid()=" << pathsJavaObj.isValid();

			jobjectArray pathArray = pathsJavaObj.object<jobjectArray>();
			int stringCount = env->GetArrayLength(pathArray);

			QStringList paths;
			for (int i=0; i<stringCount; i++)
			{
				jstring string = (jstring) env->GetObjectArrayElement(pathArray, i);
				const char *rawString = env->GetStringUTFChars(string, 0);
				// Don't forget to call `ReleaseStringUTFChars` when you're done.

				QString path(rawString);
				qDebug() << "path[]=" << path;
				paths.append(path);

				env->ReleaseStringUTFChars(string, rawString);
			}
			emit this->accepted(paths);

		}
		else if ( receiverRequestCode == 9000 )//PhotoPicker
		{
			qDebug() << __FUNCTION__ << ":code=9000";
			QAndroidJniEnvironment env;

			QAndroidJniObject PhotoPickerActivity__KEY_SELECTED_PHOTOS
					= QAndroidJniObject::getStaticObjectField(
						"me/iwf/photopicker/PhotoPickerActivity", "KEY_SELECTED_PHOTOS", "Ljava/lang/String;");
			qDebug() << "PhotoPickerActivity__KEY_SELECTED_PHOTOS.isValid()=" << PhotoPickerActivity__KEY_SELECTED_PHOTOS.isValid();

			QAndroidJniObject photos = data.callObjectMethod("getStringArrayListExtra","(Ljava/lang/String;)Ljava/util/ArrayList;",
														  PhotoPickerActivity__KEY_SELECTED_PHOTOS.object<jstring>());
			qDebug() << "photos.isValid()=" << photos.isValid();

			QAndroidJniObject photosObjectArray = photos.callObjectMethod("toArray","()[Ljava/lang/Object;");
			qDebug() << "photosObjectArray.isValid()=" << photosObjectArray.isValid();

			jobjectArray pathArray = photosObjectArray.object<jobjectArray>();
			int stringCount = env->GetArrayLength(pathArray);
			qDebug() << "pathArray=" << (void*)pathArray;
			qDebug() << "stringCount=" << stringCount;

			QStringList paths;
			for (int i=0; i<stringCount; i++)
			{
				qDebug() << "for pathArray...i=" << i;
				jstring string = (jstring) env->GetObjectArrayElement(pathArray, i);
				const char *rawString = env->GetStringUTFChars(string, 0);
				// Don't forget to call `ReleaseStringUTFChars` when you're done.
				qDebug() << "for pathArray...i=" << i << ":rawString=" << rawString;

				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 )
			{
//.........这里部分代码省略.........
开发者ID:AndrewDesign,项目名称:wpp-qt,代码行数:101,代码来源:ImagePicker.cpp


注:本文中的QAndroidJniEnvironment::GetObjectArrayElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。