try {
android.content.ContentValues values = new android.content.ContentValues();
values.put(android.provider.MediaStore.MediaColumns.DISPLAY_NAME, "测试Android13写入文件"); //file name
values.put(android.provider.MediaStore.MediaColumns.MIME_TYPE, "text/plain"); //file extension, will automatically add to file
//values.put(android.provider.MediaStore.MediaColumns.RELATIVE_PATH, android.os.Environment.DIRECTORY_DOCUMENTS + "/Kamen Rider Decade/"); //end "/" is not mandatory
android.net.Uri uri = getContentResolver().insert(android.provider.MediaStore.Files.getContentUri("external"), values); //important!
java.io.OutputStream outputStream = getContentResolver().openOutputStream(uri);
outputStream.write("This is menu category data.".getBytes());
outputStream.close();
Toast.makeText(this, "File created successfully", Toast.LENGTH_SHORT).show();
} catch (java.io.IOException e) {
Toast.makeText(this, "Fail to create file", Toast.LENGTH_SHORT).show();
}
Android13写入文件
最新推荐文章于 2023-11-14 11:27:36 发布
本文详细描述了如何在Android13环境中使用ContentValuesAPI插入文本文件,包括设置文件名、MIME类型,并尝试创建一个外部存储的文件。
5524

被折叠的 条评论
为什么被折叠?



