Add support for love.filedropped in Android.

To send file to the filedropped callback, share the files to the game.
Note that for non-fused binary, if there's no game running, LOVE treat it as
*.love game to run.
This commit is contained in:
Miku AuahDark
2022-05-29 01:49:29 +08:00
parent 2879074177
commit 7b66e50cfc
3 changed files with 52 additions and 6 deletions
+25 -5
View File
@@ -126,9 +126,6 @@ bool openURL(const std::string &url)
static jmethodID openURL = env->GetMethodID(clazz, "openURLFromLOVE", "(Ljava/lang/String;)Z");
if (openURL == nullptr)
return false;
jstring jstringURL = env->NewStringUTF(url.c_str());
jboolean result = env->CallBooleanMethod(clazz, openURL, jstringURL);
@@ -725,9 +722,9 @@ const char *getCRequirePath()
{
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jobject activity = (jobject) SDL_AndroidGetActivity();
jclass clazz = env->GetObjectClass(activity);
jclass clazz(env->GetObjectClass(activity));
jmethodID getCRequireMethod = env->GetMethodID(clazz, "getCRequirePath", "()Ljava/lang/String;");
static jmethodID getCRequireMethod = env->GetMethodID(clazz, "getCRequirePath", "()Ljava/lang/String;");
jstring cpath = (jstring) env->CallObjectMethod(activity, getCRequireMethod);
const char *utf = env->GetStringUTFChars(cpath, nullptr);
@@ -745,6 +742,29 @@ const char *getCRequirePath()
return path.c_str();
}
int getFDFromContentProtocol(const char *path)
{
int fd = -1;
if (strstr(path, "content://") == path)
{
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
jobject activity = (jobject) SDL_AndroidGetActivity();
jclass clazz = env->GetObjectClass(activity);
static jmethodID converter = env->GetMethodID(clazz, "convertToFileDescriptor", "(Ljava/lang/String;)I");
jstring uri = env->NewStringUTF(path);
fd = (int) env->CallIntMethod(activity, converter, uri);
env->DeleteLocalRef(uri);
env->DeleteLocalRef(clazz);
env->DeleteLocalRef(activity);
}
return fd;
}
int getFDFromLoveProtocol(const char *path)
{
constexpr const char PROTOCOL[] = "love2d://fd/";