blob: 6200a40ce6da73b728a61947cb375c1f41ccc1ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package de.pixart.messenger.services;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
import android.util.Log;
import de.pixart.messenger.Config;
public class EventReceiver extends BroadcastReceiver {
public static final String SETTING_ENABLED_ACCOUNTS = "enabled_accounts";
@Override
public void onReceive(Context context, Intent intent) {
Intent mIntentForService = new Intent(context, XmppConnectionService.class);
if (intent.getAction() != null) {
mIntentForService.setAction(intent.getAction());
} else {
mIntentForService.setAction("other");
}
final String action = intent.getAction();
if (action.equals("ui") || hasEnabledAccounts(context)) {
try {
context.startService(mIntentForService);
} catch (RuntimeException e) {
Log.d(Config.LOGTAG, "EventReceiver was unable to start service");
}
} else {
Log.d(Config.LOGTAG, "EventReceiver ignored action " + mIntentForService.getAction());
}
}
public static boolean hasEnabledAccounts(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SETTING_ENABLED_ACCOUNTS, true);
}
}
|