Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gradle/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Tue Nov 26 00:44:34 KST 2024
java.home=C\:\\Program Files\\Android\\Android Studio1\\jbr
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

226 changes: 226 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

android {
namespace = "com.example.assignment02"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.example.assignment02"
Expand Down Expand Up @@ -36,11 +36,11 @@ android {
}

dependencies {
implementation("androidx.activity:activity-ktx:1.7.0")
implementation("androidx.core:core-ktx:1.13.1")

implementation("androidx.core:core-ktx:1.15.0")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.constraintlayout:constraintlayout:2.2.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -21,7 +24,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RandomActivity" />
</application>

</manifest>
72 changes: 72 additions & 0 deletions app/src/main/java/com/example/assignment02/AuthorityFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.example.assignment02

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction

class AuthorityFragment : Fragment() {

private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>

override fun onAttach(context: Context) {
super.onAttach(context)

requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
openFragment()
}
}

requestPermission()
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_authority, container, false)
val authorityText = view.findViewById<TextView>(R.id.authority_text)

authorityText.setOnClickListener {
requestPermission()
}

return view
}

private fun openFragment() {
val fragmentList = ListFragment.newInstance()
parentFragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragmentList)
.addToBackStack(null)
.commit()
}

private fun requestPermission() {
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
// 권한이 이미 있음
openFragment()
} else {
// 권한이 없으면 권한 요청
requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
}
}

companion object {
fun newInstance(): AuthorityFragment {
return AuthorityFragment()
}
}
}
Loading