add a media ContentProvider

Every time the ContentProvider is accessed, a file chooser opens and the
selected file is then provided as media file.
This commit is contained in:
Julian Winkler
2025-04-23 18:13:15 +02:00
parent cff51b230b
commit 49fa854c93
7 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
#include <gtk/gtk.h>
#include <stdbool.h>
#include "../generated_headers/android_content_ATLMediaContentProvider.h"
#include "../defines.h"
#include "../util.h"
extern GtkWindow *window;
static void file_dialog_callback(GObject *dialog, GAsyncResult *res, gpointer user_data) {
GFile *file = gtk_file_dialog_open_finish(GTK_FILE_DIALOG(dialog), res, NULL);
JNIEnv *env = get_jni_env();
jobject this = (jobject) user_data;
(*env)->CallVoidMethod(env, this, _METHOD(_CLASS(this), "setSelectedFile", "(Ljava/lang/String;)V"), _JSTRING(g_file_get_path(file)));
g_object_unref(file);
_UNREF(this);
}
JNIEXPORT void JNICALL Java_android_content_ATLMediaContentProvider_native_1open_1media_1folder(JNIEnv *env, jobject this)
{
GtkFileDialog *dialog = gtk_file_dialog_new();
gtk_file_dialog_set_title(GTK_FILE_DIALOG(dialog), "Open Media Folder");
gtk_file_dialog_set_modal(GTK_FILE_DIALOG(dialog), TRUE);
gtk_file_dialog_open(dialog, window, NULL, file_dialog_callback, _REF(this));
}

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_content_ATLMediaContentProvider */
#ifndef _Included_android_content_ATLMediaContentProvider
#define _Included_android_content_ATLMediaContentProvider
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: android_content_ATLMediaContentProvider
* Method: native_open_media_folder
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_android_content_ATLMediaContentProvider_native_1open_1media_1folder
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif