在Android的SD卡 [英] SD card in Android

查看:162
本文介绍了在Android的SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用我有两个按钮,播放和下载。在downlod按钮下载我从互联网上,并存储在SD卡中的视频,我会从SD卡时preSS播放按钮播放视频。

In my app I have two buttons play and download. In the downlod button I download video from internet and store in SD card, i will play video from the SD card when press play button.

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

Video is successfully downloaded and stored in SD card. If I press play button, I will list videos from SD card(in logcat) and play the downloaded video. It does not show the downloaded video name, but if I open the SD card from my system the downloaded video is stored in SD card. i do not know where i am wrong.

推荐答案

您需要的媒体文件添加到媒体商店,以便由画廊控件可以看出。使用MediaScanner。我用这个方便的包装在我的code:

You have to add media files to Media Store in order to be seen by gallery widget. Use MediaScanner. I use this convenient wrapper in my code:

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 启动扫描()。你可以调整它在同时处理多个文件。提示:通过列表的文件的路径,然后循环回路 mConnection.scanFile

Then instantiate MediaScannerWrapper and start it with scan(). You could tweak it to handle more than one file at the time. Hint: pass List of File paths, and then loop around mConnection.scanFile.

这篇关于在Android的SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆