Last active
February 19, 2019 13:37
-
-
Save griajobag/924e83d12a4bc6337cbdb26f4784312a to your computer and use it in GitHub Desktop.
scanner
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
package com.sangcomz.fishbun.util; | |
import android.content.Context; | |
import android.media.MediaScannerConnection; | |
import android.net.Uri; | |
import java.io.File; | |
public class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient { | |
private MediaScannerConnection mMs; | |
private File mFile; | |
private ScanListener scanListener; | |
public SingleMediaScanner(Context context, File f) { | |
init(context, f); | |
} | |
public SingleMediaScanner(Context context, File f, ScanListener scanListener) { | |
init(context, f); | |
this.scanListener = scanListener; | |
} | |
private void init(Context context, File f) { | |
mFile = f; | |
mMs = new MediaScannerConnection(context, this); | |
mMs.connect(); | |
} | |
@Override | |
public void onMediaScannerConnected() { | |
mMs.scanFile(mFile.getAbsolutePath(), null); | |
} | |
@Override | |
public void onScanCompleted(String path, Uri uri) { | |
if (scanListener != null) scanListener.onScanCompleted(); | |
mMs.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment