Page 211 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 211
private Button go; //View Project 버튼
@Override
protected void onCreate(Bundle savedInstanceState){ //액티비티를 불러올때 가장 먼저
불러와지는 함수로써, Activity를 상속했다면 반드시 오버라이드 되어야 하는 함수
super.onCreate(savedInstanceState); //상위클래스에서 실행
setContentView(R.layout.activity_nfc); //사용할 레이아웃을 선택
/*data from connect Activity*/
Intent in= getIntent(); //전의 액티비티에서 보낸 정보를 받아온다.
ip = in.getStringExtra("IP"); //IP를 받아온다.(String)
port = in.getIntExtra("Port",0); //Port를 받아온다. 만약 없으면 기본값으로 0을
지정한다.(Integer)
/*Initial Button Variable and Vibrator*/
police = (ToggleButton)findViewById(R.id.Police); //변수에다가 layout에서 만든
버튼과 연동을 해준다.
hospital = (ToggleButton)findViewById(R.id.Hospital);
test = (ToggleButton)findViewById(R.id.test);
go = (Button)findViewById(R.id.viewtent);
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); //시스템에서 진
동기능을 얻어온다.
t = new Thread(this); //스레드 등록(여기 있으니 this이다.)
t.start(); //스레드 실행(소켓을 연결)
mTextView = (TextView)findViewById(R.id.NFCView);
// NFC 어댑터를 구한다
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
// NFC 어댑터가 null 이라면 칩이 존재하지 않는 것으로 간주
if( mNfcAdapter == null ) {
mTextView.setText("This phone is not NFC enable.");
return;
}
in = null; //인텐트 변수와 인텐트 클래스의 연결을 끊어버린다.(필요없으니 없애버려서 메
모리 관리 위해)
// NFC 데이터 활성화에 필요한 인텐트를 생성
- 204 -