2 回答

TA貢獻1825條經(jīng)驗 獲得超4個贊
<manifest ... >
<!-- This attribute is "false" by default on apps targeting Android Q. ->
<application android:requestLegacyExternalStorage="true" ... >
</application>
</manifest>

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
添加回答
舉報