new app that makes http request to alexmahr.de/word
This commit is contained in:
parent
56b84b40af
commit
d16df109b5
2 changed files with 104 additions and 14 deletions
|
@ -5,6 +5,8 @@
|
|||
android:versionName="3.0">
|
||||
<uses-sdk android:minSdkVersion="30"
|
||||
android:targetSdkVersion="33"/>
|
||||
<uses-permission android:name="android.permission.INTERNET">
|
||||
</uses-permission>
|
||||
<!-- android:maxSdkVersion="integer" /> -->
|
||||
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
|
||||
<activity android:name="HelloJNI"
|
||||
|
|
|
@ -4,26 +4,114 @@ import android.util.Log;
|
|||
import android.widget.TextView;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.lang.Thread;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
|
||||
class Threads1 implements Runnable {
|
||||
|
||||
public String result = "alex";
|
||||
|
||||
public void run(){
|
||||
try{
|
||||
result = result.concat("step 2\n");
|
||||
URL url = new URL("https://alexmahr.de/word");
|
||||
result = result.concat("step 3\n");
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
result = result.concat("step 4\n");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
result = result.concat("step 5\n");
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
result = result.concat("step 6\n");
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
result = result.concat("step 7\n");
|
||||
response.append(inputLine);
|
||||
}
|
||||
result = result.concat("step 8\n");
|
||||
in.close();
|
||||
result = result.concat("step 9\n");
|
||||
result = result.concat( "OK".concat(response.toString()));
|
||||
urlConnection.disconnect();
|
||||
} catch (Exception e){
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class HelloJNI extends Activity
|
||||
{
|
||||
/** Called when the activity is first created. */
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
TextView tv = new TextView(this);
|
||||
tv.setText( "hallo " );
|
||||
//stringFromJNI() );
|
||||
// tv.setText("sup");
|
||||
setContentView(tv);
|
||||
try
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
//volatile String result = "initial";
|
||||
String result = "initial";
|
||||
TextView tv = new TextView(this);
|
||||
tv.setMovementMethod(new ScrollingMovementMethod());
|
||||
Threads1 threads1 = new Threads1();
|
||||
Thread thread = new Thread(threads1);
|
||||
thread.start();
|
||||
thread.join();
|
||||
|
||||
// Thread thread = new Thread(new Runnable() {
|
||||
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// result = result.concat("step 2\n");
|
||||
// URL url = new URL("https://alexmahr.de/word");
|
||||
// result = result.concat("step 3\n");
|
||||
// HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
||||
// result = result.concat("step 4\n");
|
||||
// BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
// result = result.concat("step 5\n");
|
||||
// String inputLine;
|
||||
// StringBuffer response = new StringBuffer();
|
||||
// result = result.concat("step 6\n");
|
||||
|
||||
// while ((inputLine = in.readLine()) != null) {
|
||||
// result = result.concat("step 7\n");
|
||||
// response.append(inputLine);
|
||||
// }
|
||||
// result = result.concat("step 8\n");
|
||||
// in.close();
|
||||
// result = result.concat("step 9\n");
|
||||
// result = result.concat( "OK".concat(response.toString()));
|
||||
// urlConnection.disconnect();
|
||||
|
||||
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// thread.start();
|
||||
// thread.join();
|
||||
tv.setText( result);
|
||||
setContentView(tv);
|
||||
try{
|
||||
// TimeUnit.SECONDS.sleep(1);
|
||||
} catch (Exception e){
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
tv.setText(result.concat(threads1.result));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public native String stringFromJNI();
|
||||
|
||||
/* static {
|
||||
Log.i("amo", "Trying to load shared library!");
|
||||
System.loadLibrary("hellojni");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue