【问题标题】:How can I make custom folder (App folder's) in android 11如何在 android 11 中制作自定义文件夹(App 文件夹)
【发布时间】:2021-05-02 02:00:46
【问题描述】:
  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());

清单

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

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

第二个问题

公共静态字符串根= 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));

copyFile的函数调用

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 系统错误: java.io.FileNotFoundException: /storage/emulated/0/Download/.HidedTop/gallery_resize_video.mp4: 打开失败:EACCES(权限被拒绝)

应用在目的地崩溃 =

new FileOutputStream(destFile).getChannel();

【问题讨论】:

  • 您可以在 Documents 文件夹中创建它们。
  • @blackapps 先生,我找不到你..
  • 你的意思是我需要在 Documents 或 Downloads 文件夹中创建我的自定义目录?
  • 不是那么......我对 com.APPtop 文件夹等感到困惑,就像我们之前在 android 10 下所做的那样
  • 找到了吗?我给了你我认为的解决方案。 ;-)

标签: java android android-11


【解决方案1】:

通过使用下面的 sn-p 我的问题解决了。

Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)

.getExternalStoragePublicDirectory() 已弃用。

【讨论】:

  • 是的,这就是我告诉你要使用的。现有公共目录中您自己的文件夹。
  • @blackapps 需要你的帮助!该文件夹已成功创建,但它不起作用,就像我必须编辑和更新,复制它但每次它说“java.io.IOException:不允许操作”
  • GPUCameraRecorder: java.io.FileNotFoundException: /storage/emulated/0/Download/.HidedFolder error @blackapps 仍然应用程序无权管理它
  • @blackapps 现在从第二个问题开始检查
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-07
相关资源
最近更新 更多