Handler handler = new Handler() {
public void handleMessage(Message msg) {
textView.setText("");
// 비콘의 아이디와 거리를 측정하여 textView에 넣는다.
for(Beacon beacon : beaconList){
textView.append("Major :"+beacon.getId2()+"/"+"minor : " + beacon.getId3() + "\n");
}
// 자기 자신을 1초마다 호출
handler.sendEmptyMessageDelayed(0, 1000);
}
};
비콘 예제를 활용해서 스캐너를 구현했습니다. 그런데 비콘의 major,minor 값을 handler를 통해서 뜨는 것 말고 서버를 통해 DB에 넣고 싶은데...
어떻게 해야 major,minor값을 변수로 만들어서 다른 액티비티로 전달할 수 있을까요?
이미 작성된 php파일과 연결하기 위해서 아래처럼 request 액티비티를 따로 작성했습니다.
public class BeaconRequest extends StringRequest {
final static private String URL = "http://133.186.209.91/bus_insert.php";
private Map<String, String> map;
//private Map<String, String>parameters;
public BeaconRequest(/*String user_id*/int beacon_major,int beacon_minor, Response.Listener<String> listener) {
super(Method.POST, URL, listener, null);
map = new HashMap<>();
/*map.put("user_id", user_id);*/
map.put("beacon_major", beacon_major + "");
map.put("beacon_minor", beacon_minor + "");
}
/*php 파일, DB데이터 형식에 맞춰서 요청함*/
@Override
protected Map<String, String>getParams() throws AuthFailureError {
return map;
}
}