aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2022-06-05 17:42:09 +0100
committerGitHub <noreply@github.com>2022-06-05 17:42:09 +0100
commit4baf56520d61e22687b563d403f5d873251e135f (patch)
tree222fc895a63ac842866345d2fe216092f65134f2 /src
parenta69b7abe00fb818fd88f3cd04e7f9997ffd21072 (diff)
downloadminetest-4baf56520d61e22687b563d403f5d873251e135f.tar.gz
minetest-4baf56520d61e22687b563d403f5d873251e135f.tar.bz2
minetest-4baf56520d61e22687b563d403f5d873251e135f.zip
Android: Add support for sharing debug.txt (#12370)
Diffstat (limited to 'src')
-rw-r--r--src/porting_android.cpp12
-rw-r--r--src/porting_android.h7
-rw-r--r--src/script/lua_api/l_mainmenu.cpp14
-rw-r--r--src/script/lua_api/l_mainmenu.h2
4 files changed, 35 insertions, 0 deletions
diff --git a/src/porting_android.cpp b/src/porting_android.cpp
index c71fe5ad8..83b590b99 100644
--- a/src/porting_android.cpp
+++ b/src/porting_android.cpp
@@ -213,6 +213,18 @@ void openURIAndroid(const std::string &url)
jnienv->CallVoidMethod(app_global->activity->clazz, url_open, jurl);
}
+void shareFileAndroid(const std::string &path)
+{
+ jmethodID url_open = jnienv->GetMethodID(nativeActivity, "shareFile",
+ "(Ljava/lang/String;)V");
+
+ FATAL_ERROR_IF(url_open == nullptr,
+ "porting::shareFileAndroid unable to find java openURI method");
+
+ jstring jurl = jnienv->NewStringUTF(path.c_str());
+ jnienv->CallVoidMethod(app_global->activity->clazz, url_open, jurl);
+}
+
int getInputDialogState()
{
jmethodID dialogstate = jnienv->GetMethodID(nativeActivity,
diff --git a/src/porting_android.h b/src/porting_android.h
index 239815922..265825fbd 100644
--- a/src/porting_android.h
+++ b/src/porting_android.h
@@ -61,6 +61,13 @@ void showInputDialog(const std::string &acceptButton,
void openURIAndroid(const std::string &url);
/**
+ * Opens a share intent to the file at path
+ *
+ * @param path
+ */
+void shareFileAndroid(const std::string &path);
+
+/**
* WORKAROUND for not working callbacks from java -> c++
* get current state of input dialog
*/
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index f7b2393fb..4a847ed6d 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -877,6 +877,19 @@ int ModApiMainMenu::l_open_dir(lua_State *L)
}
/******************************************************************************/
+int ModApiMainMenu::l_share_file(lua_State *L)
+{
+#ifdef __ANDROID__
+ std::string path = luaL_checkstring(L, 1);
+ porting::shareFileAndroid(path);
+ lua_pushboolean(L, true);
+#else
+ lua_pushboolean(L, false);
+#endif
+ return 1;
+}
+
+/******************************************************************************/
int ModApiMainMenu::l_do_async_callback(lua_State *L)
{
MainMenuScripting *script = getScriptApi<MainMenuScripting>(L);
@@ -941,6 +954,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
API_FCT(get_max_supp_proto);
API_FCT(open_url);
API_FCT(open_dir);
+ API_FCT(share_file);
API_FCT(do_async_callback);
}
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 781185425..6ceff6dd7 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -152,6 +152,8 @@ private:
static int l_open_dir(lua_State *L);
+ static int l_share_file(lua_State *L);
+
// async
static int l_do_async_callback(lua_State *L);