@@ -103,6 +103,7 @@ public class MainActivity extends NativeActivity {
103
103
private static final String FOLDER_NAME = "SmallBASIC" ;
104
104
private static final int COPY_BUFFER_SIZE = 1024 ;
105
105
private static final String [] SAMPLES = {"welcome.bas" };
106
+ private static final int TIMEOUT_MILLIS = 5000 ;
106
107
private String _startupBas = null ;
107
108
private boolean _untrusted = false ;
108
109
private final ExecutorService _audioExecutor = Executors .newSingleThreadExecutor ();
@@ -382,7 +383,6 @@ public boolean loadModules() {
382
383
System .loadLibrary ("ioio" );
383
384
Class .forName ("ioio.smallbasic.android.ModuleLoader" )
384
385
.getDeclaredConstructor (Long .class , Context .class ).newInstance (getActivity (), this );
385
- consoleLog ("loadModules - success" );
386
386
result = true ;
387
387
} catch (Exception | UnsatisfiedLinkError e ) {
388
388
consoleLog (e .toString ());
@@ -509,10 +509,10 @@ public boolean removeLocationUpdates() {
509
509
return result ;
510
510
}
511
511
512
- public String request (String endPoint , String method , String data , String apiKey ) throws IOException {
512
+ public String request (String endPoint , String data , String apiKey ) throws IOException {
513
513
String result ;
514
514
try {
515
- HttpURLConnection conn = getHttpURLConnection (endPoint , method , apiKey );
515
+ HttpURLConnection conn = getHttpURLConnection (endPoint , ( data == null || data . isEmpty ()) ? "GET" : "POST" , apiKey );
516
516
if (data != null && !data .isEmpty ()) {
517
517
OutputStream os = conn .getOutputStream ();
518
518
os .write (data .getBytes (StandardCharsets .UTF_8 ));
@@ -530,10 +530,10 @@ public String request(String endPoint, String method, String data, String apiKey
530
530
in .close ();
531
531
result = response .toString ();
532
532
} else {
533
- result = "[ error:" + responseCode + "]" ;
533
+ result = "error:[ " + responseCode + "]" ;
534
534
}
535
535
} catch (Exception e ) {
536
- result = "[ error:" + e + "]" ;
536
+ result = "error:[ " + e + "]" ;
537
537
}
538
538
return result ;
539
539
}
@@ -798,21 +798,19 @@ private void execStream(InputStream inputStream) throws IOException {
798
798
}
799
799
800
800
@ NonNull
801
- private static HttpURLConnection getHttpURLConnection (String endPoint ,
802
- String method ,
803
- String apiKey ) throws IOException {
801
+ private HttpURLConnection getHttpURLConnection (String endPoint , String method , String apiKey ) throws IOException {
804
802
URL url = new URL (endPoint );
805
- HttpURLConnection conn = (HttpURLConnection ) url .openConnection ();
806
- conn .setConnectTimeout (10000 );
807
- conn .setRequestProperty ("User-Agent" , "SmallBASIC" );
808
- conn .setRequestMethod (method == null || method . isEmpty () ? "POST" : method );
809
- conn .setInstanceFollowRedirects (true );
803
+ HttpURLConnection result = (HttpURLConnection ) url .openConnection ();
804
+ result .setConnectTimeout (TIMEOUT_MILLIS );
805
+ result .setRequestProperty ("User-Agent" , "SmallBASIC" );
806
+ result .setRequestMethod (method );
807
+ result .setInstanceFollowRedirects (true );
810
808
if (apiKey != null && !apiKey .isEmpty ()) {
811
- conn .setRequestProperty ("Content-Type" , "application/json" );
812
- conn .setRequestProperty ("Authorization" , "Bearer " + apiKey );
809
+ result .setRequestProperty ("Content-Type" , "application/json" );
810
+ result .setRequestProperty ("Authorization" , "Bearer " + apiKey );
813
811
}
814
- conn .setDoOutput (true );
815
- return conn ;
812
+ result .setDoOutput (true );
813
+ return result ;
816
814
}
817
815
818
816
private Uri getSharedFile (File file ) {
0 commit comments