1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-16 18:01:40 +00:00

Android: Add support for sharing debug.txt (#12370)

This commit is contained in:
rubenwardy 2022-06-05 17:42:09 +01:00 committed by GitHub
parent a69b7abe00
commit 4baf56520d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 2 deletions

View file

@ -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,

View file

@ -60,6 +60,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

View file

@ -876,6 +876,19 @@ int ModApiMainMenu::l_open_dir(lua_State *L)
return 1;
}
/******************************************************************************/
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)
{
@ -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);
}

View file

@ -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);