pref: 去除文件保存目录名空格
This commit is contained in:
parent
deabc0600a
commit
d9f56cc885
|
|
@ -29,6 +29,8 @@ public class FileUtil {
|
||||||
public static final int FILE_TYPE_VIDEO = 1;
|
public static final int FILE_TYPE_VIDEO = 1;
|
||||||
public static final int FILE_TYPE_AUDIO = 2;
|
public static final int FILE_TYPE_AUDIO = 2;
|
||||||
|
|
||||||
|
public static final String FILE_FOLDER = "TiebaLite";
|
||||||
|
|
||||||
public static void deleteAllFiles(File root) {
|
public static void deleteAllFiles(File root) {
|
||||||
File[] files = root.listFiles();
|
File[] files = root.listFiles();
|
||||||
if (files != null)
|
if (files != null)
|
||||||
|
|
@ -52,15 +54,13 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param context 上下文对象
|
* @param context 上下文对象
|
||||||
* @param dir 存储目录
|
* @param dir 存储目录
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getFilePath(Context context, String dir) {
|
public static String getFilePath(Context context, String dir) {
|
||||||
String directoryPath = "";
|
String directoryPath = "";
|
||||||
//判断SD卡是否可用
|
//判断SD卡是否可用
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
directoryPath = context.getExternalFilesDir(dir).getAbsolutePath();
|
directoryPath = context.getExternalFilesDir(dir).getAbsolutePath();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -183,7 +183,7 @@ public class FileUtil {
|
||||||
directory = Environment.DIRECTORY_DOWNLOADS;
|
directory = Environment.DIRECTORY_DOWNLOADS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
request.setDestinationInExternalPublicDir(directory, "Tieba Lite/" + fileName);
|
request.setDestinationInExternalPublicDir(directory, FILE_FOLDER + File.separator + fileName);
|
||||||
final DownloadManager downloadManager = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
|
final DownloadManager downloadManager = (DownloadManager) context.getSystemService(DOWNLOAD_SERVICE);
|
||||||
// 添加一个下载任务
|
// 添加一个下载任务
|
||||||
if (downloadManager != null) {
|
if (downloadManager != null) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.huanchengfly.tieba.post.utils;
|
package com.huanchengfly.tieba.post.utils;
|
||||||
|
|
||||||
|
import static com.huanchengfly.tieba.post.utils.FileUtil.FILE_FOLDER;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
|
@ -233,7 +235,7 @@ public class ImageUtil {
|
||||||
}
|
}
|
||||||
new DownloadAsyncTask(context, url, file -> {
|
new DownloadAsyncTask(context, url, file -> {
|
||||||
String fileName = URLUtil.guessFileName(url, null, MimeType.JPEG.toString());
|
String fileName = URLUtil.guessFileName(url, null, MimeType.JPEG.toString());
|
||||||
String relativePath = Environment.DIRECTORY_PICTURES + File.separator + "Tieba Lite";
|
String relativePath = Environment.DIRECTORY_PICTURES + File.separator + FILE_FOLDER;
|
||||||
if (forShare) {
|
if (forShare) {
|
||||||
relativePath += File.separator + "shareTemp";
|
relativePath += File.separator + "shareTemp";
|
||||||
}
|
}
|
||||||
|
|
@ -271,15 +273,14 @@ public class ImageUtil {
|
||||||
downloadAboveQ(context, url, false, null);
|
downloadAboveQ(context, url, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
|
||||||
private static void downloadBelowQ(Context context, String url, boolean forShare, @Nullable ShareTaskCallback taskCallback) {
|
private static void downloadBelowQ(Context context, String url, boolean forShare, @Nullable ShareTaskCallback taskCallback) {
|
||||||
new DownloadAsyncTask(context, url, file -> {
|
new DownloadAsyncTask(context, url, file -> {
|
||||||
File pictureFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsoluteFile();
|
File pictureFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsoluteFile();
|
||||||
File appDir;
|
File appDir;
|
||||||
if (forShare) {
|
if (forShare) {
|
||||||
appDir = new File(pictureFolder, "Tieba Lite" + File.separator + "shareTemp");
|
appDir = new File(pictureFolder, FILE_FOLDER + File.separator + "shareTemp");
|
||||||
} else {
|
} else {
|
||||||
appDir = new File(pictureFolder, "Tieba Lite");
|
appDir = new File(pictureFolder, FILE_FOLDER);
|
||||||
}
|
}
|
||||||
if (appDir.exists() || appDir.mkdirs()) {
|
if (appDir.exists() || appDir.mkdirs()) {
|
||||||
if (forShare) {
|
if (forShare) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue