use of android.os.PowerManager in project cw-omnibus by commonsguy.
the class EventDemoActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
String pkg = getPackageName();
PowerManager pm = getSystemService(PowerManager.class);
if (!pm.isIgnoringBatteryOptimizations(pkg)) {
Intent i = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).setData(Uri.parse("package:" + pkg));
startActivity(i);
}
}
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
getFragmentManager().beginTransaction().add(android.R.id.content, new EventLogFragment()).commit();
startService(new Intent(this, ScheduledService.class));
}
}
use of android.os.PowerManager in project cw-omnibus by commonsguy.
the class ScheduledService method onCreate.
@Override
public void onCreate() {
super.onCreate();
PowerManager mgr = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getSimpleName());
wakeLock.acquire();
if (BuildConfig.IS_FOREGROUND) {
foregroundify();
}
log = new File(getExternalFilesDir(null), "antidoze-log.txt");
log.getParentFile().mkdirs();
sched.scheduleAtFixedRate(this, 0, 15, TimeUnit.SECONDS);
}
use of android.os.PowerManager in project AndroidTraining by mixi-inc.
the class DefaultModule method configure.
@SuppressWarnings("unchecked")
protected void configure() {
bind(Application.class).toProvider(ApplicationProvider.class).in(ApplicationScoped.class);
bind(Context.class).toProvider(ContextProvider.class);
bind(Handler.class).toProvider(HandlerProvider.class).in(ApplicationScoped.class);
bind(ActivityManager.class).toProvider(new SystemServiceProvider<ActivityManager>(Context.ACTIVITY_SERVICE));
bind(AlarmManager.class).toProvider(new SystemServiceProvider<AlarmManager>(Context.ALARM_SERVICE));
bind(AudioManager.class).toProvider(new SystemServiceProvider<AudioManager>(Context.AUDIO_SERVICE));
bind(ConnectivityManager.class).toProvider(new SystemServiceProvider<ConnectivityManager>(Context.CONNECTIVITY_SERVICE));
bind(InputMethodManager.class).toProvider(new SystemServiceProvider<InputMethodManager>(Context.INPUT_METHOD_SERVICE));
bind(KeyguardManager.class).toProvider(new SystemServiceProvider<KeyguardManager>(Context.KEYGUARD_SERVICE));
bind(LocationManager.class).toProvider(new SystemServiceProvider<LocationManager>(Context.LOCATION_SERVICE));
bind(NotificationManager.class).toProvider(new SystemServiceProvider<NotificationManager>(Context.NOTIFICATION_SERVICE));
bind(PowerManager.class).toProvider(new SystemServiceProvider<PowerManager>(Context.POWER_SERVICE));
bind(SensorManager.class).toProvider(new SystemServiceProvider<SensorManager>(Context.SENSOR_SERVICE));
bind(TelephonyManager.class).toProvider(new SystemServiceProvider<TelephonyManager>(Context.TELEPHONY_SERVICE));
bind(Vibrator.class).toProvider(new SystemServiceProvider<Vibrator>(Context.VIBRATOR_SERVICE));
bind(WifiManager.class).toProvider(new SystemServiceProvider<WifiManager>(Context.WIFI_SERVICE));
bind(WindowManager.class).toProvider(new SystemServiceProvider<WindowManager>(Context.WINDOW_SERVICE));
bind(mAccountManagerClass).toProvider(AccountManagerProvider.class);
bind(ObserverManager.class);
bindProviderListener(new ObserverRegister());
bind(StateManager.class).in(ApplicationScoped.class);
bind(StateEventObserver.class);
bindFieldListener(RetainState.class, new RetainStateListener());
}
use of android.os.PowerManager in project k-9 by k9mail.
the class K9AlarmManagerTest method createK9AlarmManagerWithDozeSupport.
private K9AlarmManager createK9AlarmManagerWithDozeSupport(boolean whiteListed) {
PowerManager powerManager = createPowerManager(whiteListed);
Context context = createContext(powerManager);
return new TestK9AlarmManager(context, true);
}
use of android.os.PowerManager in project qksms by moezbhatti.
the class MessagingReceiver method insertMessageAndNotify.
private void insertMessageAndNotify() {
mUri = SmsHelper.addMessageToInbox(mContext, mAddress, mBody, mDate);
Message message = new Message(mContext, mUri);
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(mContext, message.getThreadId());
// we can block it, so that the conversation list adapter knows to ignore this thread in the main list
if (BlockedConversationHelper.isFutureBlocked(mPrefs, mAddress)) {
BlockedConversationHelper.unblockFutureConversation(mPrefs, mAddress);
BlockedConversationHelper.blockConversation(mPrefs, message.getThreadId());
message.markSeen();
BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().futureBlockedConversationReceived();
// If we have notifications enabled and this conversation isn't blocked
} else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(PreferenceManager.getDefaultSharedPreferences(mContext)).contains(message.getThreadId())) {
Intent messageHandlerIntent = new Intent(mContext, NotificationService.class);
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, mUri.toString());
mContext.startService(messageHandlerIntent);
UnreadBadgeService.update(mContext);
NotificationManager.create(mContext);
} else {
// We shouldn't show a notification for this message
message.markSeen();
}
if (conversationPrefs.getWakePhoneEnabled()) {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
wakeLock.acquire();
wakeLock.release();
}
}
Aggregations