註冊在清單
<receiver android:name=".MediaScannerFinishedReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_SCANNER_FINISHED"/>
</intent-filter>
</receiver>
MEDIA_SCANNER_FINISHED行動,那麼在你的活動課聽同樣的動作
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);
}
}
謝謝約翰..讓我來試試你的代碼... – saa
Downvoted因爲接收者正在代碼和清單中註冊,這兩者都不需要。 – Meanman