Unregister receiver in ScanPreference
This commit is contained in:
parent
a9bf6e942a
commit
cd6c4ea1e9
@ -38,7 +38,6 @@ public class ScanPreference extends Preference {
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
android.util.Log.i("VanillaMusic", "receive: " + intent);
|
||||
String action = intent.getAction();
|
||||
if (action.equals(Intent.ACTION_MEDIA_SCANNER_STARTED)) {
|
||||
setSummary(R.string.scan_in_progress);
|
||||
@ -46,6 +45,7 @@ public class ScanPreference extends Preference {
|
||||
} else if (intent.getAction().equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
|
||||
setSummary(R.string.finished_scanning);
|
||||
setEnabled(true);
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -55,17 +55,17 @@ public class ScanPreference extends Preference {
|
||||
super(context, attrs);
|
||||
setTitle(R.string.media_scan);
|
||||
setSummary(R.string.click_to_scan);
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
|
||||
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
|
||||
intentFilter.addDataScheme("file");
|
||||
context.registerReceiver(mReceiver, intentFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick()
|
||||
{
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
|
||||
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
|
||||
intentFilter.addDataScheme("file");
|
||||
getContext().registerReceiver(mReceiver, intentFilter);
|
||||
|
||||
Uri storage = Uri.parse("file://" + Environment.getExternalStorageDirectory());
|
||||
getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, storage));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user