-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
didikeeLuanon
committed
Sep 15, 2020
1 parent
ffb502e
commit 6375ec6
Showing
1 changed file
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
package com.androidx.utils; | ||
|
||
import android.content.Context; | ||
import android.media.MediaScannerConnection; | ||
import android.net.Uri; | ||
|
||
import com.androidx.LogUtils; | ||
import com.androidx.media.MimeType; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* user author: didikee | ||
* create time: 9/15/20 2:01 PM | ||
* description: | ||
*/ | ||
class FileUtils { | ||
public final class FileUtils { | ||
private static final MediaScannerConnection.OnScanCompletedListener ON_SCAN_COMPLETED_LISTENER = new MediaScannerConnection.OnScanCompletedListener() { | ||
@Override | ||
public void onScanCompleted(String path, Uri uri) { | ||
LogUtils.d("FileUtils --> scanFile path: " + path + " uri: " + (uri == null ? " " : uri.toString())); | ||
} | ||
}; | ||
|
||
public static void scanFile(Context context, File file) { | ||
if (file != null) { | ||
String mimeTypeFromFilename = MimeType.getMimeTypeFromFilename(file.getName()); | ||
scanFile(context, file, mimeTypeFromFilename, null); | ||
} | ||
} | ||
|
||
public static void scanFile(Context context, File file, String mimeType, MediaScannerConnection.OnScanCompletedListener onScanCompletedListener) { | ||
if (context == null) { | ||
LogUtils.d("FileUtils --> scanFile context is null."); | ||
return; | ||
} | ||
if (file == null || !file.exists()) { | ||
return; | ||
} | ||
MediaScannerConnection.scanFile(context, new String[]{file.getAbsolutePath()}, new String[]{mimeType}, onScanCompletedListener == null ? ON_SCAN_COMPLETED_LISTENER : onScanCompletedListener); | ||
} | ||
} |