如何检测是否运行在Android上的新的媒体文件扫描(背景) [英] how to detect if is running the scan for new media files on Android (in background)

查看:496
本文介绍了如何检测是否运行在Android上的新的媒体文件扫描(背景)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动:主要与处理。
在处理活动做一个编辑操作的文件夹中文件名,然后开始扫描通过广播进行更新,而我检查时,扫描完成。

I have two activity: Main and Processing. in the Processing activity do an edit operation on the file names in a folder, and then start a scan to update via broadcast, and I check when the scan finish.

//end batch renaming operation
//start updating media store library
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory()))); 
//show toast "updating"
op_media_mounted.show();
//catch when updaitng op ends
IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_FINISHED);
filter.addDataScheme("file");                   
BroadcastReceiver mReceiver = (new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
        Toast.makeText(frm_elabora.this, "Scan complete.", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
registerReceiver(mReceiver, filter);   

我想如果扫描正在运行传递活动prevent处理。
我可以首先检查,如果扫描未运行,则启动第二处理活动?不过的了。

I would like to pass the Activity prevent processing if the scan is running. I can check first if the scan is not running, then launch the second processing activity? as this.

Button btnstart = (Button)findViewById(R.id.btn_start);
btnstart.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        if ( there_isnt_scan_for_new_media_file )
            startActivity(intent_processing);
        else{
                wait_until_ACTION_MEDIA_SCANNER_FINISHED
                startActivity(intent_processing);
        }

我需要检查这一点,因为如果我重命名文件而Android运行扫描,当我在处理活动编辑文件,在最后我找到大小为0字节的文件夹中的其他文件,如变更前。
所以我必须等待该扫描完成。我无法找到一个解决方案。

I need to check this, because if i rename the files while android running a scan, when I edit the files in the processing activity, in the end I find other files in the folder with size 0 bytes, as before the change. so I have to wait that the scan finish. i can't find a solution.

更新:
我已经发现这个

UPDATES: i've found this

    public static Uri getMediaScannerUri ()
    Since: API Level 1
    Uri for querying the state of the media scanner.

我尝试这个

    //send broadcast
    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
            Uri.parse("file://" +
            Environment.getExternalStorageDirectory())));
    //show media scanner state
    Toast.makeText(frm_elabora.this,
        MediaStore.getMediaScannerUri().toString(),
        Toast.LENGTH_SHORT).show();

和我得到的内容://媒体/无/ media_scanner永远......如果我问getMediaScannerUri()后,
 发送ACTION_MEDIA_MOUNTED,我应该得到的东西不同的内容://媒体/无/ media_scanner???

and i get "content://media/none/media_scanner" always... if i ask getMediaScannerUri() after sent ACTION_MEDIA_MOUNTED, i should get something different from "content://media/none/media_scanner" ???

推荐答案

你尝试的 MEDIA_SCANNER_VOLUME

通常当媒体扫描仪正在运行此列不为null。

Usually when the media scanner is running this column is not null.

这篇关于如何检测是否运行在Android上的新的媒体文件扫描(背景)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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