从c ++源代码中,我正在调用一个java方法,该方法将String []作为参数。 (更确切地说是JIntent ACTION_SEND的“EXTRA_MAIL字段”)。 如何将向量(或仅两个char *)转换为Java“String []”对象?我知道为了将c ++字符串转换为“Java String”(只有一个字符串),有一个“StringToJSring”函数,但是String []呢? 提前完成。
更详细一点,我正在尝试从android的c ++ builder firemonkey应用程序运行以下代码:
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNI.Net.hpp>
#include <Androidapi.Helpers.hpp>
#include <FMX.Helpers.Android.hpp>
button callback (onclick):
_di_JIntent email = TJIntent::JavaClass->init(TJIntent::JavaClass->ACTION_SEND);
email->setType(StringToJString("plain/text"));
jstring emptyString = TJNIResolver::GetJNIEnv()->NewStringUTF("");
jobjectArray data = (jobjectArray)TJNIResolver::GetJNIEnv()->NewObjectArray(2, TJNIResolver::GetJNIEnv()->FindClass("java/lang/String"), emptyString);
TJNIResolver::GetJNIEnv()->SetObjectArrayElement( data,0,TJNIResolver::GetJNIEnv()->NewStringUTF("xxx@uuu.com"));
TJNIResolver::GetJNIEnv()->SetObjectArrayElement( data,1,TJNIResolver::GetJNIEnv()->NewStringUTF("zzz@uuu.com"));
email->putExtra(TJIntent::JavaClass->EXTRA_EMAIL, data);
email->putExtra(TJIntent::JavaClass->EXTRA_SUBJECT, StringToJString("My Subject"));
email->putExtra(TJIntent::JavaClass->EXTRA_TEXT, StringToJString("My text"));
SharedActivity()->startActivity(TJIntent::JavaClass->createChooser(email, StringToJString("Choose an Email client :")));
答案 0 :(得分:0)
您可以使用env-> NewObjectArray()创建任何类的数组:
// Find the String class
jclass stringClass = (*env)->FindClass(env, "java/lang/String");
// Create a String[2]
jobjectArray arr = (*env)->NewObjectArray(env, 2, stringClass, NULL);
// Add items
(*env)->SetObjectArrayElement(env, arr, 0, stringObj1);
(*env)->SetObjectArrayElement(env, arr, 1, stringObj2);
请注意,这是未经测试的,可能需要进行一些调整。有关详细信息,请参阅documentation。