質問編集履歴

1

『該当のソースコード2』を追加

2023/01/04 15:27

投稿

bluvenz
bluvenz

スコア22

test CHANGED
File without changes
test CHANGED
@@ -28,13 +28,38 @@
28
28
  val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
29
29
  context.contentResolver.takePersistableUriPermission(it, takeFlags)
30
30
 
31
- .
31
+ .
32
- .
32
+ .
33
- .
33
+ .
34
-
35
34
  }
36
35
  ```
37
36
 
37
+
38
+
39
+ ### 該当のソースコード2
40
+ ```
41
+ private var onSelectFolderButtonClickListener = View.OnClickListener {
42
+ val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
43
+ startActivityForResult(intent, REQUEST_CODE)
44
+ }
45
+
46
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
47
+ super.onActivityResult(requestCode, resultCode, data)
48
+ if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
49
+ val uri = data?.data ?: return
50
+
51
+ contentResolver.takePersistableUriPermission(
52
+ uri,
53
+ Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
54
+ )
55
+ }
56
+
57
+ .
58
+ .
59
+ .
60
+ }
61
+
62
+ ```
38
63
 
39
64
 
40
65
  ### 試したこと