第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法使用 mkdir 在 Android Q 中創(chuàng)建文件夾

無法使用 mkdir 在 Android Q 中創(chuàng)建文件夾

嗶嗶one 2023-03-09 17:18:04
我的應(yīng)用程序在所有 android 版本中創(chuàng)建文件夾沒有問題,除了android Q,我不知道為什么我的代碼在 android q 中不起作用這是我的代碼:File dir = new File("/sdcard/test");       try{              if(dir.mkdir()) {                      Log.d("DOWNLOAD","Directory created");              } else {                     Log.d("DOWNLOAD","Directory is not created");              }            }catch(Exception e){                  e.printStackTrace();        }
查看完整描述

2 回答

?
鳳凰求蠱

TA貢獻1825條經(jīng)驗 獲得超4個贊

<manifest ... >

 <!-- This attribute is "false" by default on apps targeting Android Q. ->

  <application android:requestLegacyExternalStorage="true" ... >


 </application>

</manifest>


查看完整回答
反對 回復(fù) 2023-03-09
?
手掌心

TA貢獻1942條經(jīng)驗 獲得超3個贊

在 Q 中,如果您想要訪問不是普通音樂或媒體文件的文件,即在您的情況下,sdcard/test您需要執(zhí)行以下操作:


為了訪問另一個應(yīng)用程序創(chuàng)建的任何其他文件,包括“下載”目錄中的文件,您的應(yīng)用程序必須使用存儲訪問框架,它允許用戶選擇特定文件。


引用來源: http: //developer.android.com/preview/privacy/scoped-storage


// Here are some examples of how you might call this method.

// The first parameter is the MIME type, and the second parameter is the name

// of the file you are creating:

//

// createFile("text/plain", "foobar.txt");

// createFile("image/png", "mypicture.png");


// Unique request code.

private const val WRITE_REQUEST_CODE: Int = 43

...

private fun createFile(mimeType: String, fileName: String) {

    val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {

        // Filter to only show results that can be "opened", such as

        // a file (as opposed to a list of contacts or timezones).

        addCategory(Intent.CATEGORY_OPENABLE)


        // Create a file with the requested MIME type.

        type = mimeType

        putExtra(Intent.EXTRA_TITLE, fileName)

    }


    startActivityForResult(intent, WRITE_REQUEST_CODE)

}

示例 src https://developer.android.com/guide/topics/providers/document-provider


查看完整回答
反對 回復(fù) 2023-03-09
  • 2 回答
  • 0 關(guān)注
  • 228 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號