1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-24 02:46:50 +01:00

Send current time to device if time/timezone changes. Closes #51.

This commit is contained in:
Andreas Shimokawa 2015-05-07 23:46:18 +02:00
parent 70889e5326
commit 157deff237
3 changed files with 35 additions and 0 deletions

View File

@ -102,6 +102,13 @@
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver android:name=".externalevents.TimeChangeReceiver"
android:enabled="false" >
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
<action android:name="android.intent.action.TIME_SET" />
</intent-filter>
</receiver>
<receiver
android:name=".externalevents.K9Receiver"
android:enabled="false" >

View File

@ -16,6 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.externalevents.MusicPlaybackReceiver
import nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.PhoneCallReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.SMSReceiver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.TimeChangeReceiver;
public class GB {
public static final int NOTIFICATION_ID = 1;
@ -54,6 +55,7 @@ public class GB {
K9Receiver.class,
PebbleReceiver.class,
MusicPlaybackReceiver.class,
TimeChangeReceiver.class,
//NotificationListener.class, // disabling this leads to loss of permission to read notifications
};

View File

@ -0,0 +1,26 @@
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
public class TimeChangeReceiver extends BroadcastReceiver {
private final String TAG = this.getClass().getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (action.equals(Intent.ACTION_TIME_CHANGED) || action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
Log.i(TAG, "Time or Timezone changed, syncing with device");
Intent startIntent = new Intent(context, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
context.startService(startIntent);
}
}
}