안드로이드 287

안드로이드 특정버전 설치하는 방법/다운그레이드, 버전 내리기[Electric Eel 등등]

안드로이드 스튜디오 다운로드 페이지에 들어가면 항상 최신 버전만 설치할 수 있습니다. 구 버전을 설치하고 싶은 경우 안내되는 페이지가 있지만, 현재는 Bumble bee 미만의 버전만 다운로드 할 수 있습니다. Bumble bee 미만 버전 다운로드하기는 아래 링크에서 https://developer.android.com/studio/archive?hl=ko 즉, Electric Eel 등 Griraffe 와 Bumble bee 사이의 버전은 다운로드할 수 있는 방법이 없다는 것입니다. 진짜 없는가하면 또 그건 아닙니다. 다운로드 받는 방법은 간단합니다. 먼저 https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html 여기서..

안드로이드 2023.10.06

[안드로이드/Android] 안드로이드에서 엑셀 Excel(.xlsx) 파일 읽기, Read Excel(.xlsx) file in android

1. Apache POI 라이브러리 추가하기 dependencies { ... implementation 'org.apache.poi:poi:3.9' implementation 'org.apache.poi:poi-ooxml:3.9' ... } 버전은 3.9로 해주시면 됩니다. 최신버전인 5.2.2로 해봤는데 아래와 같은 에러가 발생했고, 저는 별다른 해결책을 찾지 못했습니다. 그래서 3.9로 진행했씁니다. 1. app/src/main 에 assets 디렉토리만들고 읽으려는 .xlsx 파일 추가하기 2. 엑셀읽어오는 함수 만들기 fun readExcel(fileName: String) { val assetManager = assets val inputStream = assetManager.open(file..

안드로이드 2023.05.24

[안드로이드/Android] 폰인지, 태블릿인지 구분하기

1. TelephonyManager val telephonyManager = getSystemService(TELEPHONY_SERVICE) as TelephonyManager if (telephonyManager.phoneType == TelephonyManager.PHONE_TYPE_NONE) { Toast.makeText(this, "Tablet", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this, "Mobile", Toast.LENGTH_SHORT).show() } 2. Configuration 완벽하게 구분되지는 않는다. sw600dp 이상이면 태블릿으로, 이하이면 폰으로 구분된다. val screenType = resources.configu..

안드로이드 2023.04.05

[안드로이드/Android] onBackPressed Deprecated

OnBackPressedDispatcher ⚠️ activity.onBackPressed 는 Deprecated 되었다. OnBackPressedDispatcher OnBackPressedDispatcher | Android Developers androidx.constraintlayout.core.motion.parse developer.android.com // 필요한 시점에 해당 코드를 추가하면 된다. val callback = object: OnBackPressedCallback(true) { override fun handleOnBackPressed() { Toast.makeText(this@MainActivity, "뒤로가기 터치", Toast.LENGTH_SHORT).show() finish..

안드로이드 2023.03.28

[안드로이드/Android] Compose 에서 onBackPressed = BackHandler

안드로이드에서 기존에 뒤로가기 버튼 눌렀을 때 동작을 커스텀 할 때 onBackPressed() 메소드를 오버라이딩했씁니다. Jetpack Compose 에서는 어떻게 구현해야 할까요? BackHandler 라는 녀석을 사용하면 되는데요. 예제 코드를 보겠습니다. 뒤로 가기 버튼을 빠르게 두 번 눌렀을 때 앱을 종료하는 코드입니다. // 뒤로 가기 두 번 눌렀을 때 앱 종료 @Composable fun BackOnPressed() { val context = LocalContext.current var backPressedState by remember { mutableStateOf(true) } var backPressedTime = 0L BackHandler(enabled = backPressedSt..

안드로이드 2023.03.16

[안드로이드/Android] Compose BottomNavBar

0. 위 디렉토리 구조를 따라 아래 1~5번을 순서대로 실행하면 됩니다. https://github.com/Parksunggyun/BottomNavigationSample GitHub - Parksunggyun/BottomNavigationSample Contribute to Parksunggyun/BottomNavigationSample development by creating an account on GitHub. github.com 1. Home, Profile, Settings @Composable fun HomeScreen() { Box( modifier = Modifier.fillMaxSize().background(Color.Red), contentAlignment = Alignment.C..

안드로이드 2023.03.14

[안드로이드/Android] Compose TextField maxLength 설정하기

// maxLength 설정하기 val maxLength = 8 OutlinedTextField( modifier = Modifier .fillMaxWidth() .padding(start = 24.dp, end = 24.dp), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), leadingIcon = { Icon(imageVector = Icons.Default.Person, contentDescription = "Birth") }, value = birth, label = { Text("생년월일") }, placeholder = { Text("19920822") }, onValueChange = { if(it.text.le..

안드로이드 2023.03.14

[안드로이드/Android] Migration SharedPreferences to EncryptedSharedPreferences

의존성추가 implementation("androidx.security:security-crypto:1.0.0") // 사용 방법 val masterKeyAlias = MasterKey .Builder(applicationContext, MasterKey.DEFAULT_MASTER_KEY_ALIAS) .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) .build() val sharedPref = EncryptedSharePreferences.create( context, // Context, "encrypted_pref_name", // 파일명 masterKeyAlias, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES25..

안드로이드 2023.03.14

[Android Compose] 안드로이드 컴포즈에서 Glide 호출하기

먼저 알맞은 버전을 build.gradle(:app) dependencies 에 의존성을 추가해주세요. implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1" GlideImage( model = imageUrl, contentDescription = getString(R.id.description), modifier = Modifier.padding(padding).clickable(onClick = onClick).fillParentMaxSize(), ) GlideImage( model = imageUrl, contentDescription = getString(R.id.description), modifier = Modifier.paddin..

안드로이드 2023.02.20

[안드로이드/Android] 안드로이드 앱 아이콘 동적 변경하기

삼성 시계 앱을 보면 앱 아이콘에 현재 시간이 표시되고 계속해서 변경되는 것을 확인할 수 있습니다. 어떻게하면 이미 설치된 앱의 아이콘을 동적으로 변경할 수 있을까요? 안드로이드에서 제공하는 PackageManager 를 사용해 변경할 수 있습니다. 1. 먼저 기본 앱 아이콘, 변경할 앱 아이콘을 준비해주세요. 2. MainActivityAlias.kt 라는 클래스를 만들고 일반 액티비티처럼 AppCompatActivity를 상속해주세요. import androidx.appcompat.app.AppCompatActivity class MainActivityAlias: AppCompatActivity() { } 3. AndroidManefest.xml 에 아래 값을 추가해주세요. 태그를 추가해주시면 됩니다..

안드로이드 2023.02.16