- @Composable
- fun CreateDocumentSample() {
- val createDocumentLauncher =
- rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/*")) {
- if (it != null) {
- ...
- }
- }
- Button(
- onClick = {
- createDocumentLauncher.launch("sample.csv")
- }
- ) {
- Text("Click")
- }
- }
mimeType を "text/csv" にし、ファイル名を "sample.csv" や "sample" にした場合、ファイル名が重複したときの "(1)" が拡張子の前になる。
- @Composable
- fun CreateDocumentSample() {
- val createDocumentLauncher =
- rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/csv")) {
- if (it != null) {
- ...
- }
- }
- Button(
- onClick = {
- createDocumentLauncher.launch("sample.csv")
- }
- ) {
- Text("Click")
- }
- }
- @Composable
- fun CreateDocumentSample() {
- val createDocumentLauncher =
- rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/csv")) {
- if (it != null) {
- ...
- }
- }
- Button(
- onClick = {
- createDocumentLauncher.launch("sample")
- }
- ) {
- Text("Click")
- }
- }
名前についている拡張子が mimeType と異なる場合その部分は拡張子とは認識されず、mimeType に基づいた拡張子がつきます。
以下では mimeType が "text/plain" でファイル名が "sample.csv" なので ".csv" は拡張子とは認識されず、実際のファイル名は "sample.csv.txt" になります。
- @Composable
- fun CreateDocumentSample() {
- val createDocumentLauncher =
- rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) {
- if (it != null) {
- ...
- }
- }
- Button(
- onClick = {
- createDocumentLauncher.launch("sample.csv")
- }
- ) {
- Text("Click")
- }
- }