Skip to content

Commit

Permalink
Merge branch 'VadimBoev-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlohr committed Oct 3, 2024
2 parents fa3e92f + 66f82b6 commit f7f8fcb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions CNFGAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {

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);
Expand Down
24 changes: 24 additions & 0 deletions CNFGEGLDriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,30 @@ void AndroidMakeFullscreen()
JAVA_CALL_DETACH
}

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)
{
//Based on https://stackoverflow.com/questions/5864790/how-to-show-the-soft-keyboard-on-native-activity
Expand Down
6 changes: 3 additions & 3 deletions simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ void HandleKey( int keycode, int bDown ) { }
void HandleButton( int x, int y, int button, int bDown ) { }
void HandleMotion( int x, int y, int mask ) { }
int HandleDestroy() { return 0; }

int main()
{
CNFGSetup( "Example App", 1024, 768 );

while(CNFGHandleInput())
while(1)
{
CNFGBGColor = 0x000080ff; //Dark Blue Background

Expand Down Expand Up @@ -57,6 +58,5 @@ int main()
//Display the image and wait for time to display next frame.
CNFGSwapBuffers();
}

printf("exiting\n");
}

0 comments on commit f7f8fcb

Please sign in to comment.