Page 223 - 2020학년도 MDP과제발표회 자료집 (통신과) (3)
P. 223
toggleButton.setOnClickListener(new View.OnClickListener() @Override
public void onClick(View view) OkHttpClient client; Request request;
if (toggleButton.isChecked()) toggleButton.setTextColor(Color.YELLOW);
// 글자색 노랑색으로 변경
Toast.makeText(Camera.this,
"LED ON",
Toast.LENGTH_SHORT).show();
// 토스트 메시지 출력 라즈베리파이에게 카메라 켜도록 지시,
client = new OkHttpClient(); request =
new Request.Builder().
url("http://192.168.43.41:5000/on").build();
//led 가 켜지게 하는 url
else
toggleButton.setTextColor(Color.BLACK);
// 글자색 검정색으로 변경
Toast.makeText(Camera.this,
"LED OFF",
Toast.LENGTH_SHORT).show();
// 토스트 메시지 출력
client = new OkHttpClient(); request = new Request.Builder().
url("http://192.168.43.41:5000/off").build();
//led 가 꺼지게 하는 url
client.newCall(request).enqueue(new Callback() @Override
public void onFailure(okhttp3.Call call, IOException e)
// 실패했을 때 동작 취소
call.cancel();
@Override
throws IOException
public void onResponse(okhttp3.
Call call, okhttp3.Response response) final String myResponse =
response.body().string();
- 232 -