-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/explore #22
Feature/explore #22
Changes from 1 commit
0d8ae9e
55f9402
c565a59
72feff4
465c1e0
c7cbefd
24a247c
8face98
c808aa9
c895fb4
ff157e5
0f5bc9b
5bb46d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package kr.co.seedocs | ||
|
||
import android.Manifest | ||
import android.app.AppOpsManager | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import android.provider.Settings | ||
import androidx.activity.ComponentActivity | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.content.ContextCompat | ||
|
||
abstract class PermissionActivity : ComponentActivity() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 권한이 Storage permission으로 한정되어 있으므로 이름을 명확하게 하는것이 좋을 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어차피 캡슐화를 할 것이라면, 스토리지 권한만을 위한 로직의 책임을 가진 class로 만들고, 사용하는 곳에서 활용하도록 하는것도 좋을 것 같아요. |
||
|
||
internal fun ComponentActivity.checkStoragePermission(): Boolean = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수들이 이미 ComponentActivity 내에 있으므로 확장함수로 구현하지 않아도 될 것 같아요. |
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
checkStoragePermissionApi30() | ||
} else { | ||
checkStoragePermissionApi19() | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.R) | ||
private fun ComponentActivity.checkStoragePermissionApi30(): Boolean { | ||
val appOps = getSystemService(AppOpsManager::class.java) | ||
val mode = appOps.unsafeCheckOpNoThrow( | ||
MANAGE_EXTERNAL_STORAGE_PERMISSION, | ||
applicationInfo.uid, | ||
packageName | ||
) | ||
|
||
return mode == AppOpsManager.MODE_ALLOWED | ||
} | ||
|
||
private fun ComponentActivity.checkStoragePermissionApi19(): Boolean { | ||
val status = | ||
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) | ||
|
||
return status == PackageManager.PERMISSION_GRANTED | ||
} | ||
|
||
internal fun ComponentActivity.requestStoragePermission() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
requestStoragePermissionApi30() | ||
} else { | ||
requestStoragePermissionApi19() | ||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.R) | ||
private fun ComponentActivity.requestStoragePermissionApi30() { | ||
val intent = Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION) | ||
|
||
startActivityForResult(intent, MANAGE_EXTERNAL_STORAGE_PERMISSION_REQUEST) | ||
} | ||
|
||
private fun ComponentActivity.requestStoragePermissionApi19() { | ||
val permissions = arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE) | ||
ActivityCompat.requestPermissions( | ||
this, | ||
permissions, | ||
READ_EXTERNAL_STORAGE_PERMISSION_REQUEST | ||
) | ||
} | ||
|
||
private companion object { | ||
private const val MANAGE_EXTERNAL_STORAGE_PERMISSION = "android:manage_external_storage" | ||
private const val MANAGE_EXTERNAL_STORAGE_PERMISSION_REQUEST = 100 | ||
private const val READ_EXTERNAL_STORAGE_PERMISSION_REQUEST = 101 | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추상화된 함수를 제공하지 않는다면 open class가 더 어울릴 것 같습니다.