Android: Add VectorToJObjectArray utility function

This commit is contained in:
JosJuice
2022-12-27 22:28:06 +01:00
parent 0b9351c194
commit b3a368ae06
6 changed files with 23 additions and 43 deletions

View File

@ -13,7 +13,20 @@ std::string GetJString(JNIEnv* env, jstring jstr);
jstring ToJString(JNIEnv* env, const std::string& str);
std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array);
jobjectArray VectorToJStringArray(JNIEnv* env, std::vector<std::string> vector);
jobjectArray VectorToJStringArray(JNIEnv* env, const std::vector<std::string>& vector);
template <typename T, typename F>
jobjectArray VectorToJObjectArray(JNIEnv* env, const std::vector<T>& vector, jclass clazz, F f)
{
jobjectArray result = env->NewObjectArray(vector.size(), clazz, nullptr);
for (jsize i = 0; i < vector.size(); ++i)
{
jobject obj = f(env, vector[i]);
env->SetObjectArrayElement(result, i, obj);
env->DeleteLocalRef(obj);
}
return result;
}
// Returns true if the given path should be opened as Android content instead of a normal file.
bool IsPathAndroidContent(const std::string& uri);