Android11创建文件夹,java - 我如何在android 11中创建自定义文件夹(应用程序文件夹的) - 堆栈内存溢出...

本文探讨了在Android 11环境下开发应用时遇到的问题,如创建自定义隐藏文件夹和处理外部存储权限。作者分享了如何在`Environment.getExternalStorageDirectory()`方法失效后,尝试使用`Environment.getExternalStoragePublicDirectory()`处理下载文件夹,并详细描述了遇到的权限错误及解决尝试。
摘要由CSDN通过智能技术生成

Im facing a problem when creating app custom folder. like

com.app和storage / .hideFolder等。

通过使用android 11(SDK API 30)设备下面的一些方法

它工作正常,但在android 11中。无法使用如下所示的方法使其即时通讯

public static String root= Environment.getExternalStorageDirectory().toString();

public static final String app_hided_folder ="/.HidedAPPTop/";

public static final String app_showing_folder ="/APPTop/";

public static final String draft_app_folder= app_hided_folder +"Draft/";

public static void make_directry(String path,Context context) {

File dir = new File(path);

if (!dir.exists())

Toast.makeText(context,

(dir.mkdirs() ? "Directory has been created" : "Directory not created"),

Toast.LENGTH_SHORT).show();

else

Toast.makeText(context, "Directory exists", Toast.LENGTH_SHORT).show();

}

函数调用

make_directry(Variables.app_hided_folder,getContext());

显现

android:requestLegacyExternalStorage="true"

>

第二个问题

public static String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();

uri是我从选择器的响应中获得的视频路径。

File video_file = new File(uri.getPath());

Log.d(Variables.tag + " new path", video_file.getAbsolutePath());

Functions.copyFile(video_file,

new File(Variables.gallery_resize_video));

复制文件的函数调用

public static void copyFile(File sourceFile, File destFile) throws IOException {

if (!destFile.getParentFile().exists())

destFile.getParentFile().mkdirs();

if (!destFile.exists()) {

destFile.createNewFile();

}

FileChannel source = null;

FileChannel destination = null;

try {

source = new FileInputStream(sourceFile).getChannel();

destination = new FileOutputStream(destFile).getChannel();

destination.transferFrom(source, 0, source.size());

} finally {

if (source != null) {

source.close();

}

if (destination != null) {

destination.close();

}

}

}

错误:新路径:/storage/emulated/0/Download/STop/MP4_20210128_225711.mp4 System.err:java.io.FileNotFoundException:/storage/emulated/0/Download/.HidedTop/gallery_resize_video.mp4:打开失败:EACCES(没有权限)

并且应用程序在目标位置崩溃=

新的FileOutputStream(destFile).getChannel();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值