diff options
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java index 15ae238..fce3fd0 100755 --- a/media/java/android/mtp/MtpDatabase.java +++ b/media/java/android/mtp/MtpDatabase.java @@ -202,12 +202,17 @@ public class MtpDatabase { public void setServer(MtpServer server) { mServer = server; + // always unregister before registering + try { + mContext.unregisterReceiver(mBatteryReceiver); + } catch (IllegalArgumentException e) { + // wasn't previously registered, ignore + } + // register for battery notifications when we are connected if (server != null) { mContext.registerReceiver(mBatteryReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); - } else { - mContext.unregisterReceiver(mBatteryReceiver); } } |