Android fixes
This commit is contained in:
@@ -17,6 +17,13 @@ void android_http_request(const char *url, const char *path, const char *data, i
|
||||
|
||||
jstring jstr = (*env)->NewStringUTF(env, url);
|
||||
jbyteArray bytes_array = (jbyteArray)((*env)->CallStaticObjectMethod(env, activityClass, (*env)->GetStaticMethodID(env, activityClass, "androidHttpRequest", "(Ljava/lang/String;)[B"), jstr));
|
||||
|
||||
if (bytes_array == NULL) {
|
||||
callback(0, 200, NULL, callbackdata);
|
||||
(*vm)->DetachCurrentThread(vm);
|
||||
return;
|
||||
}
|
||||
|
||||
jsize num_bytes = (*env)->GetArrayLength(env, bytes_array);
|
||||
jbyte *elements = (*env)->GetByteArrayElements(env, bytes_array, NULL);
|
||||
if (elements != NULL) {
|
||||
|
||||
@@ -9,21 +9,25 @@ import java.net.URL;
|
||||
class AndroidHttpRequest {
|
||||
|
||||
public static byte[] androidHttpRequest(String address) throws Exception {
|
||||
// https://developer.android.com/reference/java/net/HttpURLConnection.html
|
||||
URL url = new URL(address);
|
||||
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
|
||||
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
|
||||
try {
|
||||
// https://developer.android.com/reference/java/net/HttpURLConnection.html
|
||||
URL url = new URL(address);
|
||||
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
|
||||
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int i;
|
||||
byte[] data = new byte[4];
|
||||
while ((i = in.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, i);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
int i;
|
||||
byte[] data = new byte[4];
|
||||
while ((i = in.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, i);
|
||||
}
|
||||
buffer.flush();
|
||||
byte[] result = buffer.toByteArray();
|
||||
|
||||
urlConnection.disconnect();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
buffer.flush();
|
||||
byte[] result = buffer.toByteArray();
|
||||
|
||||
urlConnection.disconnect();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user