gpt4 book ai didi

android - Android 中的 SD 卡

转载 作者:行者123 更新时间:2023-11-29 18:19:07 26 4
gpt4 key购买 nike

在我的应用程序中,我有两个按钮播放和下载。在下载按钮中,我从互联网下载视频并将其存储在 SD 卡中,当按下播放按钮时,我将从 SD 卡播放视频。

视频已成功下载并存储到 SD 卡中。如果我按下播放按钮,我将列出 SD 卡中的视频(在 logcat 中)并播放下载的视频。它不显示下载的视频名称,但如果我从我的系统打开 SD 卡,下载的视频将存储在 SD 卡中。我不知道我哪里错了。

最佳答案

您必须将媒体文件添加到媒体商店才能被画廊小部件看到。使用 MediaScanner。我在我的代码中使用了这个方便的包装器:

public class MediaScannerWrapper implements  
MediaScannerConnection.MediaScannerConnectionClient {
private MediaScannerConnection mConnection;
private String mPath;
private String mMimeType;

// filePath - where to scan;
// mime type of media to scan i.e. "image/jpeg".
// use "*/*" for any media
public MediaScannerWrapper(Context ctx, String filePath, String mime){
mPath = filePath;
mMimeType = mime;
mConnection = new MediaScannerConnection(ctx, this);
}

// do the scanning
public void scan() {
mConnection.connect();
}

// start the scan when scanner is ready
public void onMediaScannerConnected() {
mConnection.scanFile(mPath, mMimeType);
Log.w("MediaScannerWrapper", "media file scanned: " + mPath);
}

public void onScanCompleted(String path, Uri uri) {
// when scan is completes, update media file tags
}
}

然后实例化 MediaScannerWrapper 并使用 scan() 启动它。您可以调整它以同时处理多个文件。提示:传递文件路径列表,然后循环mConnection.scanFile

关于android - Android 中的 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6482751/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com