Created
February 18, 2021 08:59
-
-
Save doyle-flutter/2bfe5207920eee6b6a961c8c540fa5d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... import 생략 | |
| public class MyIntentService extends IntentService { | |
| public MyIntentService() { | |
| super("MyIntentService"); | |
| } | |
| @Override | |
| protected void onHandleIntent(Intent intent) { | |
| ResultReceiver receiver = intent.getParcelableExtra("INTENT_KEY_RECEIVER"); | |
| Timer m = new Timer(); | |
| TimerTask mt = new TimerTask() { | |
| @Override | |
| public void run() { | |
| URL url = null; | |
| Log.d("DOY","START!"); | |
| try { | |
| Log.d("DOY","START@@"); | |
| url = new URL("http://127.0.0.1:3003/"); | |
| HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); | |
| BufferedReader reader = new BufferedReader((new InputStreamReader(httpConn.getInputStream(), "UTF-8"))); | |
| String resBodyData = reader.readLine(); | |
| int statusCode = httpConn.getResponseCode(); | |
| Log.d("DOY", resBodyData); | |
| Log.d("DOY", String.valueOf(statusCode)); | |
| if(statusCode == 200){ | |
| Bundle b = new Bundle(); | |
| b.putString("key", resBodyData); | |
| receiver.send(200, b); | |
| } | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }; | |
| m.schedule(mt,10000); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment