Added intent poll

pull/162/head
M66B 5 years ago
parent 7037171685
commit b53fb25058

@ -1571,12 +1571,17 @@ You can also automate turning synchronization on and off by sending these comman
Sending these commands will automatically turn scheduling off. Sending these commands will automatically turn scheduling off.
It is also possible to just enable/disable one account, for example the account with the name *Gmail*: It is also possible to just enable/disable one account, for example the account with the name *Gmail*:
``` ```
(adb shell) am startservice -a eu.faircode.email.ENABLE --es account Gmail (adb shell) am startservice -a eu.faircode.email.ENABLE --es account Gmail
(adb shell) am startservice -a eu.faircode.email.DISABLE --es account Gmail (adb shell) am startservice -a eu.faircode.email.DISABLE --es account Gmail
``` ```
If you just want to automate checking for new messages, you can do this:
```
(adb shell) adb shell am startservice -a eu.faircode.email.POLL
```
You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html): You can automatically send commands with for example [Tasker](https://tasker.joaoapps.com/userguide/en/intents.html):
``` ```

@ -225,6 +225,7 @@
android:foregroundServiceType="dataSync"> android:foregroundServiceType="dataSync">
<intent-filter> <intent-filter>
<action android:name="${applicationId}.POLL" />
<action android:name="${applicationId}.ENABLE" /> <action android:name="${applicationId}.ENABLE" />
<action android:name="${applicationId}.DISABLE" /> <action android:name="${applicationId}.DISABLE" />
</intent-filter> </intent-filter>

@ -33,9 +33,11 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class ServiceExternal extends Service { public class ServiceExternal extends Service {
private static final String ACTION_POLL = BuildConfig.APPLICATION_ID + ".POLL";
private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE"; private static final String ACTION_ENABLE = BuildConfig.APPLICATION_ID + ".ENABLE";
private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE"; private static final String ACTION_DISABLE = BuildConfig.APPLICATION_ID + ".DISABLE";
// adb shell am startservice -a eu.faircode.email.POLL
// adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail // adb shell am startservice -a eu.faircode.email.ENABLE --es account Gmail
// adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail // adb shell am startservice -a eu.faircode.email.DISABLE --es account Gmail
@ -44,14 +46,22 @@ public class ServiceExternal extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
Log.i("Service external create");
super.onCreate(); super.onCreate();
startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build()); startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build());
} }
@Override
public void onDestroy() {
Log.i("Service external destroy");
stopForeground(true);
super.onDestroy();
}
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
try { try {
Log.i("Received intent=" + intent); EntityLog.log(this, "Service external intent=" + intent);
Log.logExtras(intent); Log.logExtras(intent);
super.onStartCommand(intent, flags, startId); super.onStartCommand(intent, flags, startId);
@ -63,10 +73,17 @@ public class ServiceExternal extends Service {
if (!ActivityBilling.isPro(this)) if (!ActivityBilling.isPro(this))
return START_NOT_STICKY; return START_NOT_STICKY;
String action = intent.getAction();
if (ACTION_POLL.equals(action)) {
ServiceSynchronize.process(this, true);
return START_NOT_STICKY;
}
final Boolean enabled; final Boolean enabled;
if (ACTION_ENABLE.equals(intent.getAction())) if (ACTION_ENABLE.equals(action))
enabled = true; enabled = true;
else if (ACTION_DISABLE.equals(intent.getAction())) else if (ACTION_DISABLE.equals(action))
enabled = false; enabled = false;
else else
enabled = null; enabled = null;
@ -100,7 +117,7 @@ public class ServiceExternal extends Service {
return START_NOT_STICKY; return START_NOT_STICKY;
} finally { } finally {
stopForeground(true); stopSelf(startId);
} }
} }

Loading…
Cancel
Save