com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter Java Examples
The following examples show how to use
com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DexCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); Log.d(TAG, "Removing from foreground"); } } if(key.equals("dex_collection_method") || key.equals("dex_txid")){ //if the input method or ID changed, accept any new package once even if they seem duplicates Log.d(TAG, "collection method or txID changed - setting lastdata to null"); lastdata = null; } }
Example #2
Source File: G5CollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); Log.i(TAG, "Moving to foreground"); } else { service.stopForeground(true); Log.i(TAG, "Removing from foreground"); } } if(key.compareTo("run_ble_scan_constantly") == 0 || key.compareTo("always_unbond_G5") == 0 || key.compareTo("always_get_new_keys") == 0 || key.compareTo("run_G5_ble_tasks_on_uithread") == 0) { Log.i(TAG, "G5 Setting Change"); cycleScan(0); } }
Example #3
Source File: G5CollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { initScanCallback(); } advertiseTimeMS.add((long)0); service = this; foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); // final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); // registerReceiver(mPairReceiver, bondintent); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected handler = new Handler(getApplicationContext().getMainLooper()); }
Example #4
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { if (scanMeister == null) { scanMeister = new ScanMeister() .applyKnownWorkarounds() .addCallBack(this, TAG); } foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); //bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected if (CollectionServiceStarter.isDexBridgeOrWifiandDexBridge()) { Log.i(TAG, "onCreate: resetting bridge_battery preference to 0"); prefs.edit().putInt("bridge_battery", 0).apply(); //if (Home.get_master()) GcmActivity.sendBridgeBattery(prefs.getInt("bridge_battery",-1)); } cloner.dontClone( android.bluetooth.BluetoothDevice.class, android.bluetooth.BluetoothGattService.class ); final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter); Log.i(TAG, "onCreate: STARTING SERVICE: pin code: " + DEFAULT_BT_PIN); Blukon.unBondIfBlukonAtInit(); }
Example #5
Source File: DexCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { if (scanMeister == null) { scanMeister = new ScanMeister() .applyKnownWorkarounds() .addCallBack(this, TAG); } foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); //bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected if (CollectionServiceStarter.isDexBridgeOrWifiandDexBridge()) { Log.i(TAG, "onCreate: resetting bridge_battery preference to 0"); prefs.edit().putInt("bridge_battery", 0).apply(); //if (Home.get_master()) GcmActivity.sendBridgeBattery(prefs.getInt("bridge_battery",-1)); } cloner.dontClone( android.bluetooth.BluetoothDevice.class, android.bluetooth.BluetoothGattService.class ); final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter); Log.i(TAG, "onCreate: STARTING SERVICE: pin code: " + DEFAULT_BT_PIN); Blukon.unBondIfBlukonAtInit(); }
Example #6
Source File: DoNothingService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { UserError.Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); UserError.Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); UserError.Log.d(TAG, "Removing from foreground"); } } }
Example #7
Source File: DoNothingService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); UserError.Log.i(TAG, "onCreate: STARTING SERVICE"); }
Example #8
Source File: WifiCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); Log.d(TAG, "Removing from foreground"); } } }
Example #9
Source File: WifiCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); // bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected Log.i(TAG, "onCreate: STARTING SERVICE"); lastState = "Starting up " + JoH.hourMinuteString(); }
Example #10
Source File: WakeLockTrampoline.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
/** * When we receive the broadcast callback we extract the required service and start it. * The framework only releases the wakelock when onReceive returns. */ @SuppressWarnings("ConstantConditions") @Override public void onReceive(final Context context, final Intent broadcastIntent) { JoH.getWakeLock(TAG, 1000); // deliberately not released final String serviceName = broadcastIntent.getStringExtra(SERVICE_PARAMETER); UserError.Log.d(TAG, "Trampoline ignition for: " + serviceName); if (serviceName == null) { UserError.Log.wtf(TAG, "Incorrectly passed pending intent with null service parameter!"); return; } final Class serviceClass = getClassFromName(serviceName); if (serviceClass == null) { UserError.Log.wtf(TAG, "Could not resolve service class for: " + serviceName); return; } final Intent serviceIntent = new Intent(context, serviceClass); final String function = broadcastIntent.getStringExtra("function"); if (function != null) serviceIntent.putExtra("function", function); ComponentName startResult; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName())); } catch (NullPointerException e) { UserError.Log.d(TAG, "Null pointer exception in startServiceCompat"); } startResult = context.startForegroundService(serviceIntent); } else { startResult = context.startService(serviceIntent); } if (D) UserError.Log.d(TAG, "Start result: " + startResult); }
Example #11
Source File: DexShareCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); readData = new ReadDataShare(this); service = this; foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); registerReceiver(mPairReceiver, bondintent); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected }
Example #12
Source File: DexShareCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); Log.i(TAG, "Moving to foreground"); } else { service.stopForeground(true); Log.i(TAG, "Removing from foreground"); } } }
Example #13
Source File: DexCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected if(CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(getApplicationContext())){ Log.i(TAG,"onCreate: resetting bridge_battery preference to 0"); prefs.edit().putInt("bridge_battery",0).apply(); } Log.i(TAG, "onCreate: STARTING SERVICE"); }
Example #14
Source File: WifiCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected Log.i(TAG, "onCreate: STARTING SERVICE"); }
Example #15
Source File: WifiCollectionService.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); Log.d(TAG, "Removing from foreground"); } } }
Example #16
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); readData = new ReadDataShare(this); service = this; foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); registerReceiver(mPairReceiver, bondintent); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); }
Example #17
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.e("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); Log.w(TAG, "Moving to foreground"); } else { service.stopForeground(true); Log.w(TAG, "Removing from foreground"); } } }
Example #18
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); }
Example #19
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.e("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); Log.w(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); Log.w(TAG, "Removing from foreground"); } } }
Example #20
Source File: DexShareCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); Log.i(TAG, "Moving to foreground"); } else { service.stopForeground(true); Log.i(TAG, "Removing from foreground"); } } }
Example #21
Source File: WakeLockTrampoline.java From xDrip with GNU General Public License v3.0 | 5 votes |
/** * When we receive the broadcast callback we extract the required service and start it. * The framework only releases the wakelock when onReceive returns. */ @SuppressWarnings("ConstantConditions") @Override public void onReceive(final Context context, final Intent broadcastIntent) { JoH.getWakeLock(TAG, 1000); // deliberately not released final String serviceName = broadcastIntent.getStringExtra(SERVICE_PARAMETER); UserError.Log.d(TAG, "Trampoline ignition for: " + serviceName); if (serviceName == null) { UserError.Log.wtf(TAG, "Incorrectly passed pending intent with null service parameter!"); return; } final Class serviceClass = getClassFromName(serviceName); if (serviceClass == null) { UserError.Log.wtf(TAG, "Could not resolve service class for: " + serviceName); return; } final Intent serviceIntent = new Intent(context, serviceClass); final String function = broadcastIntent.getStringExtra("function"); if (function != null) serviceIntent.putExtra("function", function); ComponentName startResult; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName())); } catch (NullPointerException e) { UserError.Log.d(TAG, "Null pointer exception in startServiceCompat"); } startResult = context.startForegroundService(serviceIntent); } else { startResult = context.startService(serviceIntent); } if (D) UserError.Log.d(TAG, "Start result: " + startResult); }
Example #22
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { super.onCreate(); readData = new ReadDataShare(this); service = this; foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); final IntentFilter bondintent = new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED); registerReceiver(mPairReceiver, bondintent); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); //bgToSpeech = BgToSpeech.setupTTS(getApplicationContext()); //keep reference to not being garbage collected instance = JoH.ts(); }
Example #23
Source File: DexShareCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if(key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), service); foregroundServiceStarter.start(); Log.i(TAG, "Moving to foreground"); } else { service.stopForeground(true); Log.i(TAG, "Removing from foreground"); } } }
Example #24
Source File: DexCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { if (scanMeister == null) { scanMeister = new ScanMeister() .applyKnownWorkarounds() .addCallBack(this, TAG); } foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); //bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected if (CollectionServiceStarter.isDexBridgeOrWifiandDexBridge()) { Log.i(TAG, "onCreate: resetting bridge_battery preference to 0"); prefs.edit().putInt("bridge_battery", 0).apply(); //if (Home.get_master()) GcmActivity.sendBridgeBattery(prefs.getInt("bridge_battery",-1)); } cloner.dontClone( android.bluetooth.BluetoothDevice.class, android.bluetooth.BluetoothGattService.class ); final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter); Log.i(TAG, "onCreate: STARTING SERVICE: pin code: " + DEFAULT_BT_PIN); Blukon.unBondIfBlukonAtInit(); }
Example #25
Source File: DoNothingService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { UserError.Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); UserError.Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); UserError.Log.d(TAG, "Removing from foreground"); } } }
Example #26
Source File: DoNothingService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); UserError.Log.i(TAG, "onCreate: STARTING SERVICE"); }
Example #27
Source File: WifiCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { if (key.compareTo("run_service_in_foreground") == 0) { Log.d("FOREGROUND", "run_service_in_foreground changed!"); if (prefs.getBoolean("run_service_in_foreground", false)) { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), dexCollectionService); foregroundServiceStarter.start(); Log.d(TAG, "Moving to foreground"); } else { dexCollectionService.stopForeground(true); Log.d(TAG, "Removing from foreground"); } } }
Example #28
Source File: WifiCollectionService.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); // bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected Log.i(TAG, "onCreate: STARTING SERVICE"); lastState = "Starting up " + JoH.hourMinuteString(); }
Example #29
Source File: WakeLockTrampoline.java From xDrip with GNU General Public License v3.0 | 5 votes |
/** * When we receive the broadcast callback we extract the required service and start it. * The framework only releases the wakelock when onReceive returns. */ @SuppressWarnings("ConstantConditions") @Override public void onReceive(final Context context, final Intent broadcastIntent) { JoH.getWakeLock(TAG, 1000); // deliberately not released final String serviceName = broadcastIntent.getStringExtra(SERVICE_PARAMETER); UserError.Log.d(TAG, "Trampoline ignition for: " + serviceName); if (serviceName == null) { UserError.Log.wtf(TAG, "Incorrectly passed pending intent with null service parameter!"); return; } final Class serviceClass = getClassFromName(serviceName); if (serviceClass == null) { UserError.Log.wtf(TAG, "Could not resolve service class for: " + serviceName); return; } final Intent serviceIntent = new Intent(context, serviceClass); final String function = broadcastIntent.getStringExtra("function"); if (function != null) serviceIntent.putExtra("function", function); ComponentName startResult; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && BuildConfig.targetSDK >= Build.VERSION_CODES.N && ForegroundServiceStarter.shouldRunCollectorInForeground()) { try { UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName())); } catch (NullPointerException e) { UserError.Log.d(TAG, "Null pointer exception in startServiceCompat"); } startResult = context.startForegroundService(serviceIntent); } else { startResult = context.startService(serviceIntent); } if (D) UserError.Log.d(TAG, "Start result: " + startResult); }
Example #30
Source File: DexCollectionService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void onCreate() { if (scanMeister == null) { scanMeister = new ScanMeister() .applyKnownWorkarounds() .addCallBack(this, TAG); } foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this); foregroundServiceStarter.start(); //mContext = getApplicationContext(); dexCollectionService = this; prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); listenForChangeInSettings(); //bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected if (CollectionServiceStarter.isDexBridgeOrWifiandDexBridge()) { Log.i(TAG, "onCreate: resetting bridge_battery preference to 0"); prefs.edit().putInt("bridge_battery", 0).apply(); //if (Home.get_master()) GcmActivity.sendBridgeBattery(prefs.getInt("bridge_battery",-1)); } cloner.dontClone( android.bluetooth.BluetoothDevice.class, android.bluetooth.BluetoothGattService.class ); final IntentFilter pairingRequestFilter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST); pairingRequestFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); registerReceiver(mPairingRequestRecevier, pairingRequestFilter); Log.i(TAG, "onCreate: STARTING SERVICE: pin code: " + DEFAULT_BT_PIN); Blukon.unBondIfBlukonAtInit(); }