Android
-
[Android] 파일 공유 대응 방법(File Provider)Android 2020. 11. 13. 10:46
Android 7.0 이상 버전부터는 파일 공유시에 정책이 변경되었습니다. 그래서 제대로 코드를 짰지만 파일 공유가 안되는 일을 겪으실 수 있습니다. 파일 경로를 file:// 을 사용하면 Fileuriexposedexception가 발생합니다. 안드로이드에서는 파일 공유시 접근 권한을 반드시 줘야하고 content://로 시작 해야합니다. 그리고 FileProvider를 사용하기를 권장하고 있습니다. FileProvider는 xml에 사용하는 경로별로 정의를 해 줘야 합니다.1. res/xml/provider.xml 2. Manifest 이 두 가지를 설정해주면 FileProvider를 사용하여 파일을 공유 할 수 있습니다.
-
[Android] 카카오 로그인 v2 API with kotlin - 1Android 2020. 10. 16. 18:03
카카오 로그인을 공부하면서 사용하는 방법을 정리 해볼까 합니다. 일단 카카오 내어플리케이션에 들어가서 앱을 등록 해줘야합니다. 앱 아이콘에는 앱에 사용할 아이콘 이미지를 넣어 주시면됩니다. 앱 이름은 스토어에 올릴 때 사용할 이름을 적어 주시면 됩니다. 사업자명은 회사명이나 개인 앱이라면 닉네임을 적어 주시면 됩니다. 그 다음 등록된 애플리케이션에 들어가줍니다. 플랫폼을 눌러 Android 플랫폼 등록을 들어가줍니다. 패키지명에는 로그인 기능을 넣을 프로젝트의 패키지명을 입력해주시면 됩니다. 마켓 URL는 런칭 했을때 다운로드 받을 수 있는 URL을 의미합니다. 키 해시는 디버그 키와 릴리즈 키가 있습니다. 디버그 키는 개발 환경에서 로그인 기능을 사용하려면 필수적으로 입력해야하고 릴리즈 키는 구글 스토..
-
Fragment 통신 (setTargetFragment, Listener)Android 2020. 10. 7. 17:11
많은 방법들이 있겠지만 setTargetFragment와 Listener를 생성해주는것 중에 생각이 들었습니다. dialog.setTargetFragment(this, DialogNumber.DIALOG_OFTEN) setTargetFragment는 이런식으로 dialog에 fragment와 code 값을 넘겨줍니다. targetFragment?.onActivityResult(targetRequestCode, Activity.RESULT_OK, Intent()) dialog에서 특정 이벤트 발생시 다시 통신을 보냅니다. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult..
-
BindingAdapter에서 margin 설정하기Android 2020. 9. 24. 14:26
리사이클러 뷰를 사용하다보면 아이템마다 다르게 margin값을 설정해야 할 때가 있다. 그럴때 BindingAdapter를 사용하여 margin을 설정해줄 수 있다. data class TextData( override val marginStart: Int, override val marginEnd: Int, override val marginTop: Int, override val marginBottom: Int ) : BaseTextData margin만 설명을 하자면 Data 클래스에 아이템별로 margin 값을 담아놔준다. (text 나 size등을 설정 할때도 동일하다.) val Int.dp: Int get() { val metrics = Resources.getSystem().displayMe..
-
[Android] TaskAndroid 2020. 9. 2. 18:50
개념 Task란 특정 작업을 수행할 때 사용자와 상호 작용하는 Activity를 back stack에 쌓아둔 것을 말합니다. 새 작업을 시작하거나 홈 버튼을 통해 홈 화면으로 이동할 때 '백그라운드'로 이동할 수 있는 응집 단위입니다. stack으로 구성되어 있어 LIFO(Last In First out) 방식을 사용합니다. 최초로 실행된 Activity를 Root Activity라고 부르며 어플리케이션을 실행 했을 때 back stack에 쌓입니다. 마지막으로 실행된 Activity를 Top Activity라고 부르며 현재 화면에 보여지고 있는 Activity를 의미합니다. 홈 버튼을 눌러 홈 화면으로 나간 뒤 새로운 앱을 실행 시키더라도 이전 앱의 task는 사라지지 않습니다. 이전 앱의 task는 ..
-
Koin 입문기Android 2020. 9. 2. 18:48
Koin이란? Koin은 순수 코틀린으로 사용하는 DI를 위한 라이브러리 입니다. Dagger에 비해 학습곡선이 낮아 쉽게 사용할 수 있습니다. DI란? 의존성 주입(Dependency Injection)의 줄임말 입니다. A라는 클래스가 B라는 클래스를 참조하고 있으면 A가 B에게 의존성을 갖는다고 할 수 있습니다. 그러므로 B 클래스가 변경이 되면 의존성을 갖는 A 클래스도 같이 변경 해야 한다는 문제점이 있습니다. 이러한 문제점을 의존성 주입을 통해서 해결을 할 수 있습니다. DI를 사용하면 이러한 장점들이 있습니다. 재사용성을 높여줍니다. 테스트에 용이합니다. 코드를 단순화 시켜줍니다. 종속된 코드를 줄여줍니다. 결합도를 낮추면서 유연성과 확장성이 향상됩니다. DI에 관련된 공부는 이 프로젝트를 ..
-
Dialog Fragment round cornersAndroid 2020. 9. 2. 18:46
Layout ... ... drawable/dialog_round_corners dialogFragment class CustomDialog : DialogFragment() { override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.dialog_detail_info, container,false) dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) dialog?.window?.requestFeature(Window..
-
Android key hash 구하기Android 2020. 9. 2. 18:45
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) try { val info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES) val signatures = info.signingInfo.apkContentsSigners val md = MessageDigest.getInstance("SHA") for (signature in signatures) { val md: MessageDigest md = MessageDigest.ge..