我已经设法解决了。从“ Android 中的 SD 卡”中获取一些代码
new MediaScannerWrapper(ctx, mostRecentRecording.getFullPath(), "audio/*").scan();
ctx.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + PathsHandler.getInstance().getRecordingsDirectory())));
下面是我从上面提到的帖子中获取的 MediaScannerWrapper:
public class MediaScannerWrapper implements MediaScannerConnectionClient {
private MediaScannerConnection mConnection;
private String mPath;
private String mMimeType;
public MediaScannerWrapper(Context ctx, String filePath, String mime){
mPath = filePath;
mMimeType = mime;
mConnection = new MediaScannerConnection(ctx, this);
}
public void scan(){
mConnection.connect();
}
@Override
public void onMediaScannerConnected() {
mConnection.scanFile(mPath, mMimeType);
Log.d(getClass().getName(), "Media file scanned: "+mPath);
}
@Override
public void onScanCompleted(String arg0, Uri arg1) {
}
}