Skip to content

Conversation

@kimseokhyeon1210
Copy link

real aggignment 9

@kimseokhyeon1210 kimseokhyeon1210 changed the title 9 assignment [김석현_ Android] 9주차 과제 제출 Jun 23, 2025
Copy link

@KYM-P KYM-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOOD

private fun showPermissionDeniedDialog() {
AlertDialog.Builder(this)
.setTitle("권한 필요!")
.setMessage("음악 파일을 표시하려면 권한이 필요합니다.\n\nAllow permission to show files")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.xml 써주세요.
기본적으로 사용자에게 보이는 메시지나 텍스트는 strings.xml을 사용하여 유지보수가 편리하게 만드는게 맞습니다.

) { isGranted ->
if (isGranted) {
loadMusicFiles()
Toast.makeText(this, "allow", Toast.LENGTH_SHORT).show()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.xml 사용이 필요합니다.

Copy link
Contributor

@kongwoojin kongwoojin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다.
코멘트 확인해주세요

import androidx.recyclerview.widget.RecyclerView
import java.io.File

data class MusicItem(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별도의 data class로 분리 바랍니다


private fun loadMusicFiles() {

val file = File("/sdcard/Music/Lil_Tecca_Dark_Thoughts.mp3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped storage 도입 후, /sdcard에 직접 접근이 불가합니다.
따라서 이 코드는 동작하지 않습니다.

private fun loadMusicFiles() {

val file = File("/sdcard/Music/Lil_Tecca_Dark_Thoughts.mp3")
if (file.exists()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일이 존재하는지 확인해서 미디어 스캐닝을 시도하려고 하신 것 같은데, 이렇게 되면 파일이 존재할 때 미디어 스캐닝이 동작합니다.
또한, 위에서 말한것 처럼, /sdcard에 대한 접근이 불가하기 때문에, 작동하지 않습니다.

미디어 스캐닝을 시도하시려면 미디어 스캐닝을 시도하는 버튼을 만드시는게 좋아보입니다.

미디어 스캐닝을 앱 실행 시 매번 실행하면 되는거 아니냐고 생각하실 수 있는데, 미디어 스캐닝 자체가 꽤 무거운 작업이라 필요할 때만 실행해야 합니다.

MediaScannerConnection.scanFile(this, arrayOf(file.absolutePath), null, null)
}

if (file.exists()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

마찬가지입니다

}
}

musicAdapter.notifyDataSetChanged()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notifyDataSetChanged의 경우, adapter 내의 데이터를 한꺼번에 업데이트 하는 코드입니다.
musicList.add 밑어 musicAdapter.notifyItemInserted(musicList.lastIndex)를 호출하는게 더 좋을 것 같습니다

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recyclerview의 아이템에 사용하는 xml 파일은 activity라는 이름을 가져선 안됩니다.
일반적으로 item_music과 같은 이름을 사용합니다.

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activity_permission이 아니라 activity_main에 있어야 하는 내용입니다.

<string name="notification_channel_random" translatable="false" tools:ignore="ExtraTranslation">random</string>
<string name="channel_text" translatable="false" tools:ignore="ExtraTranslation">text</string>
<string name="result" translatable="false">Result: %1$d</string>
<string name="app_name" tools:ignore="DuplicateDefinition">Music Player</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app_name이 두번 선언되어 있습니다.


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 권한입니다.


class MainActivity : AppCompatActivity() {

private lateinit var recyclerView: RecyclerView
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecyclerView를 굳이 lateinit으로 선언할 이유가 없어 보입니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants