因为第一次安装软件后,File.mkdirs()方法创建文件夹失败,去网上找到了原因在这里
文件路径原本用的是Environment.getExternalStorageDirectory(),现在改为context.getFilesDir().getAbsolutePath()

import android.os.Environment;

import java.io.File;

public class SDCardUtil {
    /*public static String getInnerSDCardPath() {
        return Environment.getExternalStorageDirectory() + File.separator;
    }*/
    
    public static String getInnerSDCardPath() {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            File external = MainApplication.getContext().getExternalFilesDir(null);
            if (external != null) {
                return external.getAbsolutePath() + File.separator;
            }
        }
        return MainApplication.getContext().getFilesDir().getAbsolutePath() + File.separator;
    }
}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐