본문 바로가기
반응형

Android56

[Android] Email 보내기 Email Intent Intent.ACTION_SEND 로 이메일 보내기 간단한 static method 생성 public class EmailUtils { public static void sendEmailToAdmin(Context context, String title, String[] receivers){ Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_SUBJECT, title); email.putExtra(Intent.EXTRA_EMAIL, receivers); email.putExtra(Intent.EXTRA_TEXT, String.format("App Version : %s\nDevice : %s\nAndroid(SDK) : .. 2020. 4. 21.
[Android] 코드에서 속도 체크 SystemClock uptimeMillis 코드 속도 체크 SystemClock.uptimeMillis() 속도 체크를 하고 싶은 시작 부분에 Long start = SystemClock.uptimeMillis(); 종료 부분에 Long end = SystemClock.uptimeMillis(); Log.d("#SPEEDTEST", "for using stream : " + (end-start) + "ms"); 테스트 stream 을 이용한 loop 와 그냥 for loop 의 속도를 비교해볼까요? // stream 이용 Long start = SystemClock.uptimeMillis(); filteredList = orgList.stream().filter(f->isTagExists(f.getTag(), tagList)).collect(Co.. 2020. 4. 8.
[Android] getColor From Resource Color Resource 에서 color 가져오기 Activity 에서 ContextCompat.getColor(getApplicationContext(), R.color.your_color_id) Fragment 에서 getActivity().getColor(R.color.your_color_id) Hex String 에서 Color.parseColor("#FFFFFF") 2020. 4. 8.
[Android] Battery check. 배터리 정보 가져오기 Android Battery 배터리 정보 조회 PowerConnectionReceiver.java public class PowerConnectionReceiver extends BroadcastReceiver { private BatteryResultCallback batteryResultCallback; public PowerConnectionReceiver(BatteryResultCallback batteryResultCallback){ this.batteryResultCallback = batteryResultCallback; } @Override public void onReceive(Context context, Intent intent) { try { int status = intent.ge.. 2020. 3. 18.
[Android] Array resource. getStringArray 가 항상 null 일때 getStringArray always return null elements values > arrays.xml 을 사용할 때 0 1 2 이렇게 작성 후 소스에서 String[] typesArr = getResources().getStringArray(R.array.array_types_value); 이렇게 불러올 때가 있죠. 이렇게 했을 때 값들은 모두 null 입니다. 이유는 해당 array 의 값은 모두 int 형이라서 단순히 array tag 를 쓰면 int 로 됩니다. String 으로 가져오려면 resource 에 string array 라고 명시를 해야합니다. 0 1 2 2020. 3. 18.
[Android] Landscape 시 알아둬야 할 점 Android Landscape 가로모드로 변경하도록 하는 방법이 두가지가 있는데 1. programmatically 하게 onCreate 에서 코드로 바꾸는 방법 2. manifest 에서 설정하는 방법 결론부터 말씀드리면 1번을 사용하면 어디에 해당 activity 가 다시 시작될 수 있습니다. (onCreate->onDestroy->onCreate) 2번은 별 이슈가 없습니다. 저의 경우엔 1번 방법을 사용했고 onDestroy 에서 thread 를 죽이는 작업을 하고있었는데 가끔식 오류가 발생하더라고요. 이 Activity 를 실행하면 onDestroy() 가 호출됩니다. 헐 뭥미.. 아래와 같이 onCreate에 코드로 바꾸는 방법을 사용하면 화면이 다시 시작될 수 있다고 합니다 @Overrid.. 2020. 3. 12.
[Android] androidx 에서 File 공유하기, File Share androidx file share androidx 파일 공유 결과 화면입니다. app > res > xml > file_provider.xml 을 생성합니다. file_provider.xml AndroidManifest.xml app > manifests > AndroidManifest.xml 에 부분을 추가합니다. 사용( Activity 에서 ) File extRoot = getExternalFilesDir(null); String someFile = "/test/some.xls"; File xlsFile = new File(extRoot, someFile); Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("appli.. 2020. 3. 3.
[Android] Get only file name from path (파일명만 가져오기) get file name from file path 파일path에서 파일명만 가져오기 변수 타입에따라 골라서 쓰면 되겠죠~ File을 사용하는 방법. File file = new File("/storage/sdcard0/DCIM/Camera/hello_bryan.jpg"); String strFileName = file.getName(); Log.d("TEST", strFileName);// -> hello_bryan.jpg substring 사용 방법. String path = "/storage/sdcard0/DCIM/Camera/hello_bryan.jpg"; String filename=path.substring(path.lastIndexOf("/")+1); Uri 일때 Uri.getLastPath.. 2020. 3. 3.
[Android] File copy 방법 몇개 Android File copy 파일 복사 API26+ @RequiresApi(api = Build.VERSION_CODES.O) public static void copy(File origin, File dest) throws IOException { Files.copy(origin.toPath(), dest.toPath()); } FileChannel 이용하는 방법 (2GB 이하만 가능) public void copy(File src, File dst) throws IOException { FileInputStream inStream = new FileInputStream(src); FileOutputStream outStream = new FileOutputStream(dst); FileChanne.. 2020. 3. 3.
[Android] BuildConfig 변수 생성/사용하기 BuildConfig 변수. 변수 선언 1. build.gradle 의 defaultConfig { 안에 } 사용합니다. defaultConfig { applicationId "your project" minSdkVersion 26 targetSdkVersion 29 versionCode 1 versionName "1.0" buildConfigField "String", "SOME_KEY", '"gDE4g5DFghsf5523HDSFdfg"' } buildConfigField 는 위와 같이 사용할수도있고 buildConfigField("String", "SOME_KEY", '"thisIsSomeKeyString"') 이렇게 사용할 수 도 있습니다. 그리고 debug 와 release 에 따라 다르게 사용하.. 2020. 3. 2.
728x90
반응형