diff --git a/misc/export/android/MediaHelperAndroid.java b/misc/export/android/MediaHelperAndroid.java new file mode 100644 index 00000000..07688902 --- /dev/null +++ b/misc/export/android/MediaHelperAndroid.java @@ -0,0 +1,47 @@ + +/* Copy this to /app/src/main/java/org/libsdl/app/MediaHelperAndroid.java */ + +package org.libsdl.app; + +import android.content.Context; + +import java.lang.Class; +import java.lang.reflect.Method; + +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.io.OutputStreamWriter; +import java.io.BufferedWriter; + +public class MediaHelperAndroid { + + public static String httpRequest(String urlstr, String data) throws Exception { + String content = "", line; + try { + URL url = new URL(urlstr); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + if (data == null) { + connection.setRequestMethod("GET"); + } else { + connection.setRequestMethod("POST"); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream())); + writer.write(data); + writer.flush(); + writer.close(); + } + connection.setConnectTimeout(5000); + connection.setReadTimeout(5000); + connection.connect(); + BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); + while ((line = rd.readLine()) != null) { + content += line + "\n"; + } + } catch (Exception ex) { + return ex.getMessage(); + } + return content; + } +} \ No newline at end of file diff --git a/misc/export/android/citrine.c b/misc/export/android/citrine.c index 66e1b532..bb329309 100644 --- a/misc/export/android/citrine.c +++ b/misc/export/android/citrine.c @@ -14,6 +14,25 @@ extern JNIEXPORT jstring JNICALL Java_com_citrine_citrineandroid_MainActivity_st } */ +ctr_object* ctr_network_basic_text_send(ctr_object* myself, ctr_argument* argumentList) { + ctr_object* rs; + char* data = ctr_heap_allocate_cstring(ctr_internal_cast2string(argumentList->object)); + char* url = ctr_heap_allocate_cstring(ctr_internal_cast2string(argumentList->next->object)); + JNIEnv* env = (JNIEnv*) SDL_AndroidGetJNIEnv(); + jclass mha = (*env)->FindClass(env, "org/libsdl/app/MediaHelperAndroid"); + jmethodID mid = (*env)->GetStaticMethodID(env, mha, "httpRequest", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"); + jstring jurl=(*env)->NewStringUTF(env, url); + jstring jdata=(*env)->NewStringUTF(env, data); + jstring result = (jstring) (*env)->CallStaticObjectMethod(env,mha, mid, jurl, jdata); + const char* nativeString = (const char*) (*env)->GetStringUTFChars(env, result, 0); + rs = ctr_build_string_from_cstring( (char*) nativeString); + (*env)->ReleaseStringUTFChars(env, result, nativeString); + (*env)->DeleteLocalRef(env, jurl); + (*env)->DeleteLocalRef(env, jdata); + ctr_heap_free(url); + ctr_heap_free(data); + return rs; +} static char* embedded_program = "\ Media _datastart.\