List of usage examples for android.os PowerManager isScreenOn
@Deprecated public boolean isScreenOn()
From source file:android_network.hetnet.vpn_service.Util.java
public static boolean isInteractive(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH) return (pm != null && pm.isScreenOn()); else/*from w ww. ja v a2 s.co m*/ return (pm != null && pm.isInteractive()); }
From source file:com.haarman.pebblenotifier.pebble.PebbleNotifier.java
private boolean shouldNotify(@NotNull final App app) { if (app.isMuted()) { return false; }//from w ww.j a va 2 s . c o m PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (powerManager.isScreenOn() && !mPreferences.shouldSendWhenScreenOn()) { return false; } if (app.getLastNotified().plusMillis(IGNORE_INTERVAL_MILLIS).isAfterNow()) { return !mPreferences.shouldIgnoreMultipleNotifications(); } return true; }
From source file:nodomain.freeyourgadget.gadgetbridge.externalevents.PebbleReceiver.java
@Override public void onReceive(Context context, Intent intent) { Prefs prefs = GBApplication.getPrefs(); if ("never".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { return;//from ww w . j av a2 s . c o m } if ("when_screen_off".equals(prefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (powermanager.isScreenOn()) { return; } } String messageType = intent.getStringExtra("messageType"); if (!messageType.equals("PEBBLE_ALERT")) { LOG.info("non PEBBLE_ALERT message type not supported"); return; } if (!intent.hasExtra("notificationData")) { LOG.info("missing notificationData extra"); return; } NotificationSpec notificationSpec = new NotificationSpec(); notificationSpec.id = -1; String notificationData = intent.getStringExtra("notificationData"); try { JSONArray notificationJSON = new JSONArray(notificationData); notificationSpec.title = notificationJSON.getJSONObject(0).getString("title"); notificationSpec.body = notificationJSON.getJSONObject(0).getString("body"); } catch (JSONException e) { e.printStackTrace(); return; } if (notificationSpec.title != null) { notificationSpec.type = NotificationType.UNKNOWN; String sender = intent.getStringExtra("sender"); if ("Conversations".equals(sender)) { notificationSpec.type = NotificationType.CONVERSATIONS; } else if ("OsmAnd".equals(sender)) { notificationSpec.type = NotificationType.GENERIC_NAVIGATION; } GBApplication.deviceService().onNotification(notificationSpec); } }
From source file:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java
/** * Called when message is received./*from w w w . j a v a2 s .com*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) { Log.d(TAG, "Message: " + message); try { JSONObject object = new JSONObject(message); ArrayList<String> eventItem = new ArrayList<>(); eventItem.add(object.toString()); broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem); if (!GameSingleton.activityForeground) { if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID) && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) { GameMessageTopic topic = GameMessageTopic .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC)); ChallengeMessage challengeMessage = new ChallengeMessage(topic, object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID), object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)); Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : " + challengeMessage.getChallengerId()); Intent intent2 = new Intent(this, DeviceListActivity.class); intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!") .setContentText("challenged by " + challengeMessage.getChallengerName()) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build()); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); if (isScreenOn == false) { PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock"); wl.acquire(10000); PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock"); wl_cpu.acquire(10000); } GameSingleton.pendingChallengeMessage = challengeMessage; GameSingleton.pendingChallenge = true; } } } catch (JSONException e) { e.printStackTrace(); } } }
From source file:com.frostwire.android.gui.NotificationUpdateDemon.java
@SuppressWarnings("deprecation") private boolean isScreenOn() { PowerManager pm = (PowerManager) mParentContext.getSystemService(Context.POWER_SERVICE); return pm != null && pm.isScreenOn(); }
From source file:com.mathi_amorim.emmanuel.metrictime.UpdateTimeService.java
public boolean isScreenOn() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); boolean screenOn = false; for (Display display : dm.getDisplays()) { if (display.getState() != Display.STATE_OFF) { screenOn = true;/* www. j a v a2s . c o m*/ } } return screenOn; } else { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); //noinspection deprecation return pm.isScreenOn(); } }
From source file:com.spoiledmilk.ibikecph.map.MapFragmentBase.java
@Override public void onPause() { SMLocationManager.getInstance().removeUpdates(); this.locationOverlay.disableMyLocation(); super.onPause(); PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); boolean isScreenOn = powerManager.isScreenOn(); if (!isScreenOn) { isReturnFromLock = true;//w ww. j a v a 2 s . c o m lastScrollX = mapView.getScrollX(); lastScrollY = mapView.getScrollY(); LOG.d("SMMapFragment onPause, scroll = " + lastScrollX + ", " + lastScrollY); } }
From source file:de.ub0r.android.portaltimer.UpdateReceiver.java
private void schedNext(final Context context) { Log.d(TAG, "schedNext()"); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Log.d(TAG, "current: " + mNow); long t;/*from w ww . ja v a2 s.co m*/ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (pm.isScreenOn()) { t = mNow + 1000L; } else { t = mNextTarget - mNow; Log.d(TAG, "t: " + t); if (t < 0) { // IllegalState? t = 30000; } else if (t < 30000) { t = 5000; } else if (t < 60000) { t = 15000; } else { t = 30000; } Log.d(TAG, "t: " + t); long diff = mNextTarget - (mNow + t); diff = (diff / 5000) * 5000; Log.d(TAG, "diff: " + diff); if (diff == 0) { t = mNow + 5000; } else { t = mNextTarget - diff - 1000; } } Log.d(TAG, "next: " + t); long et; if (t - System.currentTimeMillis() < 100) { // IllegalState? et = 1000 + SystemClock.elapsedRealtime(); } else { et = t - System.currentTimeMillis() + SystemClock.elapsedRealtime(); } am.set(AlarmManager.ELAPSED_REALTIME, et, PendingIntent.getBroadcast(context, 0, new Intent(context, UpdateReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT)); }
From source file:com.spoiledmilk.ibikecph.map.MapFragmentBase.java
@Override public void onResume() { super.onResume(); LOG.d("MapFragmentBase onResume"); this.locationOverlay.enableMyLocation(this.locationOverlay.getMyLocationProvider()); SMLocationManager locManager = SMLocationManager.getInstance(); locManager.init(getActivity(), this); if (locManager.hasValidLocation()) { refreshMapTileSource(locManager.getLastValidLocation()); } else {/*from w ww . j a v a 2 s . c om*/ mapView.setTileSource(TileSourceFactory.getTileSource(TileSourceFactory.IBIKECPH.name())); } if (!SMLocationManager.getInstance().isGPSEnabled()) { launchGPSDialog(); } ScaledTilesOverlay scaledTilesOverlay = new ScaledTilesOverlay(mapView.getTileProvider(), getActivity()); mapView.getOverlayManager().setScaledTilesOverlay(scaledTilesOverlay); PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); boolean isScreenOn = powerManager.isScreenOn(); if (isReturnFromLock && isScreenOn) { isReturnFromLock = false; if (mapView.tracking) { Location loc = SMLocationManager.getInstance().hasValidLocation() ? SMLocationManager.getInstance().getLastValidLocation() : SMLocationManager.getInstance().getLastKnownLocation(); if (loc != null) { onLocationChanged(loc); } } else { mapView.scrollTo(lastScrollX, lastScrollY); } } }
From source file:org.mozilla.gecko.tests.BaseRobocopTest.java
/** * Ensure that the screen on the test device is powered on during tests. *///from ww w . ja va2 s .c o m public void throwIfScreenNotOn() { final PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); mAsserter.ok(pm.isScreenOn(), "Robocop tests need the test device screen to be powered on.", ""); }