Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter#shouldRunCollectorInForeground()
The following examples show how to use
com.eveningoutpost.dexdrip.UtilityModels.ForegroundServiceStarter#shouldRunCollectorInForeground() .
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: 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 2
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 3
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 4
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); }