From 391bc026ce12bf86721bb3aa4484cbbf4b657e32 Mon Sep 17 00:00:00 2001 From: Kronka <33985574+Kronka@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:13:21 +0300 Subject: [PATCH 1/4] add const char* AndroidGetExternalFilesDir() --- CNFGEGLDriver.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index 4faeafc..a67ae7f 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -559,6 +559,29 @@ void AndroidMakeFullscreen() jnii->DetachCurrentThread( jniiptr ); } +const char* AndroidGetExternalFilesDir() +{ + const struct JNINativeInterface * env = 0; + const struct JNINativeInterface ** envptr = &env; + const struct JNIInvokeInterface ** jniiptr = gapp->activity->vm; + const struct JNIInvokeInterface * jnii = *jniiptr; + + jnii->AttachCurrentThread( jniiptr, &envptr, NULL); + env = (*envptr); + jclass activityClass = env->FindClass( envptr, "android/app/NativeActivity"); + jobject lNativeActivity = gapp->activity->clazz; + + jmethodID mid_getExtStorage = env->GetMethodID(envptr,activityClass,"getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;"); + jobject obj_File = env->CallObjectMethod(envptr,lNativeActivity, mid_getExtStorage, NULL); + jclass cls_File = env->FindClass(envptr,"java/io/File"); + jmethodID mid_getPath = env->GetMethodID(envptr,cls_File, "getPath", "()Ljava/lang/String;"); + jstring obj_Path = (jstring) env->CallObjectMethod(envptr,obj_File, mid_getPath); + const char* path = env->GetStringUTFChars(envptr,obj_Path, NULL); + //printf("EXTERNAL PATH = %s\n", path); + env->ReleaseStringUTFChars(envptr,obj_Path, path); + jnii->DetachCurrentThread( jniiptr ); + return path; +} void AndroidDisplayKeyboard(int pShow) { From 8ffa1bff07ff0c9ace16721933ce0bdb4b24c153 Mon Sep 17 00:00:00 2001 From: Kronka <33985574+Kronka@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:14:11 +0300 Subject: [PATCH 2/4] add const char* AndroidGetExternalFilesDir(); --- CNFGAndroid.h | 1 + 1 file changed, 1 insertion(+) diff --git a/CNFGAndroid.h b/CNFGAndroid.h index ff51dd5..2e72f3c 100644 --- a/CNFGAndroid.h +++ b/CNFGAndroid.h @@ -6,6 +6,7 @@ extern struct android_app * gapp; void AndroidMakeFullscreen(); +const char* AndroidGetExternalFilesDir(); int AndroidHasPermissions(const char* perm_name); void AndroidRequestAppPermissions(const char * perm); void AndroidDisplayKeyboard(int pShow); From 660cd85461170f099640ff708f823cc58ee3377f Mon Sep 17 00:00:00 2001 From: Kronka <33985574+Kronka@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:16:34 +0300 Subject: [PATCH 3/4] Update simple.c --- simple.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/simple.c b/simple.c index bd94148..50a1cbb 100644 --- a/simple.c +++ b/simple.c @@ -61,3 +61,27 @@ int main() CNFGSwapBuffers(); } } + +//writes the text to a file to path (example): /storage/emulated/0/Android/data/org.yourcompany.name/ +void Log(const char *fmt, ...) +{ + const char* getpath = AndroidGetExternalFilesDir(); + char buffer[0xFF]; + sprintf(buffer, "%s/log.txt", getpath); + FILE *f = fopen(buffer, "w"); + if (f == NULL) + { + exit(1); + } + + memset(buffer, 0, sizeof(buffer)); + + va_list arg; + va_start(arg, fmt); + vsnprintf(buffer, sizeof(buffer), fmt, arg); + va_end(arg); + + fprintf(f, "%s\n", buffer); + + fclose(f); +} From 2b4301270ed354897171871620715700bf0c221d Mon Sep 17 00:00:00 2001 From: Kronka <33985574+Kronka@users.noreply.github.com> Date: Sat, 17 Apr 2021 20:17:35 +0300 Subject: [PATCH 4/4] Update simple.c --- simple.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/simple.c b/simple.c index 50a1cbb..97cefa2 100644 --- a/simple.c +++ b/simple.c @@ -10,9 +10,13 @@ void HandleKey( int keycode, int bDown ) { } void HandleButton( int x, int y, int button, int bDown ) { } void HandleMotion( int x, int y, int mask ) { } void HandleDestroy() { } + +void Log(const char *fmt, ...); + int main() { CNFGSetup( "Example App", 1024, 768 ); + Log("Main started"); while(1) { CNFGBGColor = 0x000080ff; //Dark Blue Background