简体   繁体   English

我怎么知道媒体扫描完成了?

[英]How do i know media scanning completed?

I am using following code to refresh SDCard 我正在使用以下代码刷新SDCard

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));

I think it is sending one broadcast to media xxxx receiver. 我认为它正在向媒体xxxx接收器发送一个广播。 I would like to update my view after completion of work by that receiver. 我希望在接收者完成工作后更新我的观点。 How can i do that? 我怎样才能做到这一点?

Register for MEDIA_SCANNER_FINISHED action in manifest 在清单中注册MEDIA_SCANNER_FINISHED操作

<receiver android:name=".MediaScannerFinishedReceiver">
   <intent-filter>
   <action android:name="android.intent.action.MEDIA_SCANNER_FINISHED"/>
   </intent-filter>
</receiver>

Then in your activity class listen for the same action 然后在您的活动类中侦听相同的操作

BroadcastReceiver mMediaScannerReceiver;
public void registerMediaScannerListener() {
            if (mMediaScannerReceiver == null) {
                    mMediaScannerReceiver = new BroadcastReceiver() {
                            @Override
                            public void onReceive(Context context, Intent intent) {
                                    String action = intent.getAction();
                                    if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
                                            System.out.println("I'm here!");
                                    }
                            }
                    };
                    IntentFilter iFilter = new IntentFilter();
                    iFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
                    registerReceiver(mMediaScannerReceiver, iFilter);
            }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM