mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Added intent poll
This commit is contained in:
parent
7037171685
commit
b53fb25058
3 changed files with 28 additions and 5 deletions
7
FAQ.md
7
FAQ.md
|
@ -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.
|
||||
|
||||
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.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):
|
||||
|
||||
```
|
||||
|
|
|
@ -225,6 +225,7 @@
|
|||
android:foregroundServiceType="dataSync">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="${applicationId}.POLL" />
|
||||
<action android:name="${applicationId}.ENABLE" />
|
||||
<action android:name="${applicationId}.DISABLE" />
|
||||
</intent-filter>
|
||||
|
|
|
@ -33,9 +33,11 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
|
||||
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_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.DISABLE --es account Gmail
|
||||
|
||||
|
@ -44,14 +46,22 @@ public class ServiceExternal extends Service {
|
|||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.i("Service external create");
|
||||
super.onCreate();
|
||||
startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.i("Service external destroy");
|
||||
stopForeground(true);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
try {
|
||||
Log.i("Received intent=" + intent);
|
||||
EntityLog.log(this, "Service external intent=" + intent);
|
||||
Log.logExtras(intent);
|
||||
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
@ -63,10 +73,17 @@ public class ServiceExternal extends Service {
|
|||
if (!ActivityBilling.isPro(this))
|
||||
return START_NOT_STICKY;
|
||||
|
||||
String action = intent.getAction();
|
||||
|
||||
if (ACTION_POLL.equals(action)) {
|
||||
ServiceSynchronize.process(this, true);
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
final Boolean enabled;
|
||||
if (ACTION_ENABLE.equals(intent.getAction()))
|
||||
if (ACTION_ENABLE.equals(action))
|
||||
enabled = true;
|
||||
else if (ACTION_DISABLE.equals(intent.getAction()))
|
||||
else if (ACTION_DISABLE.equals(action))
|
||||
enabled = false;
|
||||
else
|
||||
enabled = null;
|
||||
|
@ -100,7 +117,7 @@ public class ServiceExternal extends Service {
|
|||
|
||||
return START_NOT_STICKY;
|
||||
} finally {
|
||||
stopForeground(true);
|
||||
stopSelf(startId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue