안드로이드/개발코드
-
volley로 post request 코드안드로이드/개발코드 2022. 2. 16. 14:45
volley로 post 요청을 할 때는 아래와 같이 하기. 헤더는 getHeaders() 로 넣고 body 내용은 getParams() 로 넣으면 되기. // Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url = "포스트 요청 넣을 http 서버"; // Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.POST, url, response -> { Log.d(tag, "Response is : " + response); }, error -> {..
-
웹에 존재하는 파일 Stream을 이용해서 다운로드 하기안드로이드/개발코드 2014. 1. 29. 17:54
String src="http://192.168.1.106/football.3gp";String des="sdcard/temp1357.3gp"; InputStream in = null; OutputStream out = null; try{ in = new BufferedInputStream(new URL(src).openStream()); out = new BufferedOutputStream(new FileOutputStream(des)); int read; while(true){ read = in.read(); if(read == -1) break; out.write(read); } in.close(); out.close(); finish(); } catch (FileNotFoundException ..
-
AlertDialog 사용하기안드로이드/개발코드 2014. 1. 29. 17:49
AlertDialog 는 동작시에 새로운 창이뜨면서 공지, 정보입력, 안내 등의 유용한 기능을 하는 안드로이드 윈도우입니다.어떻게 활성화 시키고 사용하는지 간단하게 코드로 알아봅시다. AlertDialog 창 만들기new AlertDialog.Builder(this).setTitle("타이틀 명").setMessage("메세지").setIcon(R.drawable.icon).setCancelable(false)// true이면 뒤로가기 버튼을 누르면 AlertDialog 꺼짐.setPositiveButton("확인", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int whichButton) {// 확..
-
안드로이드의 Timer 기능안드로이드/개발코드 2014. 1. 29. 17:40
예제 1>class Test extends Activity {class MyTask extends TimerTask {public void run() {Log.d("myTask", "run()");}} protected void onCreate(Bundle savedInstanceState) {Timertimer = new Timer();MyTaskmyTask = new MyTask();//timer.schedule(myTask, 500);timer.schedule(myTask, 500, 3000); super.onCreate(savedInstanceState);}} 타이머 사용에 실패했던 이유는 timerTask를 어떻게 만들까? 였는데,,클래스를 만들면 되는 거였다. 예제 2>TimerTask myT..
-
안드로이드 전체화면 만들기 (상태바, 타이틀바 제거)안드로이드/개발코드 2011. 2. 18. 00:18
앱을 만들다보면 종종 타이틀바가 없거나 타이틀바와 상태바가 없는 풀화면 어플(주로 게임)을 볼 수 있는데 이걸 어떻게 코드로 구현하나 봅시다. 상태바, 타이틀바 제거 (풀스크린 모드 만들기) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(window.FEATURE_NO_TITLE); getWindow().setFlags(WidowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); } // 혹은 AndroidMan..
-
버튼 선언과 클릭 이벤트 리스너 설정 방법안드로이드/개발코드 2011. 2. 17. 18:15
안드로이드에서 코딩작업 하면서 가장 기초중의 기초! 버튼 선언하는 방법과 선언한 버튼에 이벤트 리스너 부착하는 방법을 알아보겠습니다. 우선 버튼 선언을 하시는 구문은 아래와 같습니다. Button btn = (Button)findViewById(R.id.btn); 멤버 변수로 선언 뒤에 메서드 내에서 필요할 때마다 호출하는 방법은 다음과 같습니다. public class example extends Activity { Button btn; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button)findViewById(R.id.b..