본문 바로가기

안드로이드 개발/개발팁

안드로이드 알림창 띄우기 [Android] 알림창 띄우기 AlertDialog 안드로이드의 대표적인 알림창인 AlertDialog만 사용해도 사용자 인터페이스에서 필요한 대부분의 대화 상자를 구현할 수 있다. AlertDialog를 생성하기 위해서 먼저 AlertDialog.Builder 객체를 생성하고 이 객체의 메소드들을 호출해서 속성을 지정하고 생성한다. 1. 메세지와 확인/취소 버튼이 있는 알림창 AlertDialog.Builder builder = new AlertDialog.Builder(this); // 여기서 this는 Activity의 this // 여기서 부터는 알림창의 속성 설정builder.setTitle("종료 확인 대화 상자") // 제목 설정.setMessage("앱을 종료 하시 겠습니까?") // 메.. 더보기
Android의 Context ( getBaseContext()와 getApplicationContext() 차이) Android의 Context 정리 1) getBaseContext() Activity의 Context 생성자나 Context에서 기본 설정 된 Context 2) getApplicationContext() Service의 Context 어플리케이션의 종료 이후에도 활동 가능한 글로벌한 Application의 Context 앱 종료 후 메모리 유지를 피하기 위해서 getBaseContext를 사용. 3) View.getContext() 현재 실행되고 있는 View의 context를 return 하는데 보통은 현재 활성화된 activity의 context가 된다. 4) Activity.getApplicationContext() 어플리케이션의 Context가 return된다. 현재 activiy의 conte.. 더보기
한국나이 계산하기 FROM yyyymmdd format yyyymmdd format으로부터 한국나이 계산 public static int calculateAgeForKorean(String ssn) { // ssn의 형식은 yyyymmdd 임 String today = ""; // 오늘 날짜 int manAge = 0; // 만 나이 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); today = formatter.format(new Date()); // 시스템 날짜를 가져와서 yyyyMMdd 형태로 변환 // today yyyyMMdd int todayYear = Integer.parseInt(today.substring(0, 4)); int todayMonth = Integer.parseInt.. 더보기
JSON String을 JSONObject로 변환하기 JSON String을 JSONObject로 변환하기 자바 또는 안드로이드 통신을 하기 위해 타입은 스트링(String)이지만 데이터 값은 JSON 상태를 가지고 있을 수 있다. 예) String test = {"text" : [ { "code" : "011", "responsetext" : "응답입니다." } ] }; (문법 무시) 이런식을 어떻게 파싱해야 되는지 고민했는데 다행히 JSONObject로 변경할수 있는 방법이 있었네요 JSONObject json = null; json = new JSONObject(test); 참고 블로그 : http://heavenow.tistory.com/23 더보기
쌓여있는 액티비티 모두 지우기 쌓여있는 액티비티 모두지우기 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 더보기
폴더 생성및 삭제 폴더생성 및 폴더삭제 public static File makeDirectory(String dir_path) { File dir = new File(dir_path); if (!dir.exists()) { dir.mkdirs(); } return dir; } public static int deleteDir(String path) { File file = new File(path); if (file.exists()) { File[] childFileList = file.listFiles(); for (File childFile : childFileList) { if (childFile.isDirectory()) { deleteDir(childFile.getAbsolutePath()); } else { .. 더보기
패스를 통해서 비트map 만들기 패스를 통해서 비트map 만들기 String path = m_strSavaImagePath; // 이미지 경로 int width = m_ivPhoto.getWidth(); int height = m_ivPhoto.getHeight(); Bitmap bitmap = getBitmapFromPath(path, width, height); public static Bitmap getBitmapFromPath(String path, int targetWidth, int targetHeight) { BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeF.. 더보기
동그랗게 랜더링하기(비트맵) 동그랗게 랜더링하기(비트맵) m_ivPhoto.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); int width = m_ivPhoto.getMeasuredWidth(); int height = m_ivPhoto.getMeasuredHeight(); if(bitmap != null) { bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true); bitmap = getRoundedBitmap(bitmap, width, height); m_ivPhoto.setImageBitmap(bitmap); public static Bitmap getRoundedBitmap(Bitmap bitmap, int .. 더보기
자바(안드로이드) 오늘날짜 , 이번달의 마지막날짜 구하기 자바(안드로이드) 오늘날짜 , 이번달의 마지막날짜 구하기 GregorianCalendar today = new GregorianCalendar ( ); int year = today.get ( today.YEAR ); int month = today.get ( today.MONTH ) + 1; int day = today.get ( today.DAY_OF_MONTH ); m_strRequestFromDate = String.format("%d-%02d-%02d", year ,month,day ); // 오늘 날짜 int maxday = today.getActualMaximum ( ( today.DAY_OF_MONTH ) ); m_strRequestToDate = String.format("%d-%02d-.. 더보기
ArrayList 인텐트를 통해서 전달받기 ArrayList 인텐트를 통해서 전달받기 보내는쪽 intent.putExtra("SelectedImagesPath", sArrayList ); =============================================================================================== 받는쪽 Bundle bundle = intent.getExtras(); SelectedimagePathArr = (ArrayList) bundle .get("SelectedImagesPath"); 더보기