04-26 07:30
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- KB
- CHAT GPT
- java
- 예금
- kotlin
- RETROFIT
- MG더뱅킹정기예금
- 고금리
- ndk r24
- 새마을금고
- arm-linux-androideabi
- ndkVersion
- BindingAdapter
- 용산 호반써밋 에이디션
- 청약
- Android
- gradle
- Mac
- JetPack
- Swift
- ChatGPT
- EditText
- 달러예금
- 사전청약
- Andorid
- ios
- Android Studio
- Data Binding
- 3rd framework
- audio record
Archives
- Today
- Total
pear
[android]Scoped Storage(SAF) 본문
fun createExtenalUrl(resultLauncher: ActivityResultLauncher<Intent>){
val filename = "test.pcm"
val saf = SAFManager()
val uriSeparator = "%2F"
val path = "test${uriSeparator.toString()}sub"
saf.oepnExplore(path, filename, resultLauncher)
}
fun onActivityResult(activityesult: ActivityResult, activity: AppCompatActivity){
println("[File]onActivityResult(${activityesult.resultCode})")
println("[File]onActivityResult(${activityesult.data?.data})")
if (activityesult.resultCode == AppCompatActivity.RESULT_OK) {
activityesult.data?.data?.let {
try {
// val ofs = activity.contentResolver.openOutputStream(it as Uri)
// ofs?.writer()
// ofs?.close()
} catch (e: Exception) {
ALOG.e("[File]onActivityResult(${activityesult.data})")
e.printStackTrace()
}
}
}
}
package com.selvy.srclientsamplek.util
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.DocumentsContract
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
class SAFManager{
val TAG = this.javaClass.simpleName
fun oepnExplore(path:String, filename:String, resultLauncher:ActivityResultLauncher<Intent>){
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/*"
flags = Intent.FLAG_GRANT_WRITE_URI_PERMISSION
putExtra(Intent.EXTRA_TITLE, filename)
//[Todo] target {path} "content://com.android.externalstorage.documents/document/primary%3A{path}"
val uri = Uri.parse("content://com.android.externalstorage.documents/document/primary%3A$path")
ALOG.i(TAG, String.format("[File]path(path)"))
ALOG.i(TAG, String.format("[File]path_uri(${uri.path})"))
// val file = File("/sdcard/Documents/")
// val docFile = DocumentFile.fromFile(file)
// ALOG.i(TAG, String.format("[File]path_uri(${docFile.uri})"))
putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri)
}
resultLauncher.launch(intent)
// val intentA = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
// val file = File(Environment.getExternalStorageDirectory().getPath() + File.separator + "AWav/test_stt_kor1.pcm")
// val docFile = DocumentFile.fromFile(file)
// ALOG.i(TAG, String.format("[File]path_uri(${docFile.uri})"))
// val uri = Uri.parse("content://com.android.externalstorage.documents/document/primary%3Alogs%2F")
// type = "application/*"
// putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri)
// }
// resultLauncher.launch(intentA)
}
}
'android' 카테고리의 다른 글
[android]Extenal File Access(over android 10) (0) | 2023.12.19 |
---|---|
[android] solved Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.9.0-runtime (0) | 2023.12.11 |
[android]okhttp & Retrofit (0) | 2023.08.10 |
[android] Thread와 Handler (0) | 2023.08.09 |
[android] List View and Recycler View (0) | 2023.08.09 |