|
1 | 1 | package com.aware; |
2 | 2 |
|
| 3 | +import android.content.BroadcastReceiver; |
3 | 4 | import android.content.ContentResolver; |
| 5 | +import android.content.Context; |
4 | 6 | import android.content.Intent; |
| 7 | +import android.content.IntentFilter; |
5 | 8 | import android.content.SyncRequest; |
6 | 9 | import android.os.Bundle; |
7 | 10 | import android.util.Log; |
8 | 11 |
|
9 | | -import com.aware.providers.Keyboard_Provider; |
10 | 12 | import com.aware.providers.Notes_Provider; |
11 | 13 | import com.aware.syncadapters.Notes_Sync; |
12 | 14 | import com.aware.utils.Aware_Sensor; |
@@ -34,6 +36,22 @@ public void onCreate() { |
34 | 36 | Log.d(TAG, "Notes service created!"); |
35 | 37 | } |
36 | 38 |
|
| 39 | + |
| 40 | + private final BroadcastReceiver noteReceiver = new BroadcastReceiver() { |
| 41 | + @Override |
| 42 | + public void onReceive(Context context, Intent intent) { |
| 43 | + if (intent.getAction() != null) { |
| 44 | + switch (intent.getAction()) { |
| 45 | + case Aware.ACTION_AWARE_SYNC_DATA: |
| 46 | + Bundle sync = new Bundle(); |
| 47 | + sync.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); |
| 48 | + sync.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); |
| 49 | + ContentResolver.requestSync(Aware.getAWAREAccount(context), Notes_Provider.AUTHORITY, sync); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + }; |
| 54 | + |
37 | 55 | @Override |
38 | 56 | public void onDestroy() { |
39 | 57 | super.onDestroy(); |
@@ -66,12 +84,18 @@ public int onStartCommand(Intent intent, int flags, int startId) { |
66 | 84 | .setExtras(new Bundle()).build(); |
67 | 85 | ContentResolver.requestSync(request); |
68 | 86 | } |
69 | | - |
| 87 | + registerNoteReceiver(); |
70 | 88 | Log.d(TAG, "Sync configured for authority: " + Notes_Provider.getAuthority(this)); |
71 | 89 | Log.d(TAG, "Is syncable: " + ContentResolver.getIsSyncable(Aware.getAWAREAccount(this), Notes_Provider.getAuthority(this))); |
72 | 90 | Log.d(TAG, "Auto sync: " + ContentResolver.getSyncAutomatically(Aware.getAWAREAccount(this), Notes_Provider.getAuthority(this))); |
73 | 91 | } |
74 | 92 |
|
75 | 93 | return START_STICKY; |
76 | 94 | } |
| 95 | + |
| 96 | + private void registerNoteReceiver(){ |
| 97 | + IntentFilter filter = new IntentFilter(); |
| 98 | + filter.addAction(Aware.ACTION_AWARE_SYNC_DATA); |
| 99 | + registerReceiver(noteReceiver, filter); |
| 100 | + } |
77 | 101 | } |
0 commit comments