List of usage examples for android.content Context POWER_SERVICE
String POWER_SERVICE
To view the source code for android.content Context POWER_SERVICE.
Click Source Link
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;//from w w w. j a v a 2 s.c om } } return screenOn; } else { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); //noinspection deprecation return pm.isScreenOn(); } }
From source file:edu.tjhsst.ion.gcmFrame.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM data received.// w w w .java2 s. c om * title * text * url * sound * ongoing * wakeup */ private void sendNotification(Bundle data) { Vibrator vib = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); int vibrate = Integer.parseInt(data.getString("vibrate", "0")); if (vibrate > 0) { vib.vibrate(vibrate); } String[] vibratepattern = data.getString("vibrate", "").split(","); long[] vibpattern = new long[vibratepattern.length]; int i = 0; for (String p : vibratepattern) { vibpattern[i++] = Long.parseLong(p); } if (vibratepattern.length > 0) { vib.vibrate(vibpattern, -1); } String notif_title = data.getString("title", ""); String notif_text = data.getString("text", ""); String notif_url = data.getString("url", ""); String notif_strsound = data.getString("sound", ""); String notif_strongoing = data.getString("ongoing", ""); String notif_strwakeup = data.getString("wakeup", ""); boolean notif_sound = notif_strsound.equals("true"); boolean notif_ongoing = notif_strongoing.equals("true"); boolean notif_wakeup = notif_strwakeup.equals("true"); Intent intent; if (notif_url.length() > 0) { intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(notif_url)); } PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); PowerManager.WakeLock wl = null; if (notif_wakeup) { Log.d("showNotification", "Wakeup enabled"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // FIXME: FULL_WAKE_LOCK is deprecated wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); wl.acquire(500); } // NotificationCompat supports API level 12 NotificationCompat.Builder n = new NotificationCompat.Builder(this).setContentTitle(notif_title) .setContentText(notif_text).setSmallIcon(R.drawable.ic_stat_ic_notification) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_ic_notification)) .setContentIntent(pIntent).setAutoCancel(true).setOngoing(notif_ongoing) .setTicker(notif_title + ": " + notif_text); if (notif_sound) { n.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = n.build(); notificationManager.notify(0, notif); if (notif_wakeup) { wl.release(); } }
From source file:com.snt.bt.recon.services.BcScanService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { //leave cpu on wl = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wlTag2"); wl.acquire();// ww w.j av a 2 s .co m HandlerThread handlerThread = new HandlerThread("ht"); handlerThread.start(); Looper looper = handlerThread.getLooper(); handler = new Handler(looper); //show notification showNotification(); if (intent != null) { final String action = intent.getAction(); if (ACTION_START_SCAN.equals(action)) { //final String param1 = intent.getStringExtra(EXTRA_LAT); sessionId = UUID.fromString(intent.getStringExtra(EXTRA_SID)); handleActionStartScan(); } } return START_STICKY; }
From source file:com.nick.scalpel.core.AutoFoundWirer.java
private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme, Field field, Object forWho) { Resources resources = context.getResources(); switch (type) { case STRING://from w ww . ja va 2s .c o m setField(field, forWho, resources.getString(idRes)); break; case COLOR: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, resources.getColor(idRes, theme)); } else { //noinspection deprecation setField(field, forWho, resources.getColor(idRes)); } break; case INTEGER: setField(field, forWho, resources.getInteger(idRes)); break; case BOOL: setField(field, forWho, resources.getBoolean(idRes)); break; case STRING_ARRAY: setField(field, forWho, resources.getStringArray(idRes)); break; case INT_ARRAY: setField(field, forWho, resources.getIntArray(idRes)); break; case PM: setField(field, forWho, context.getSystemService(Context.POWER_SERVICE)); break; case ACCOUNT: setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE)); break; case ALARM: setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE)); break; case AM: setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE)); break; case WM: setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE)); break; case NM: setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE)); break; case TM: setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE)); break; case TCM: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE)); } break; case SP: setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context)); break; case PKM: setField(field, forWho, context.getPackageManager()); break; case HANDLE: setField(field, forWho, new Handler(Looper.getMainLooper())); break; case ASM: setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE)); break; case CAP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE)); } break; case KGD: setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE)); break; case LOCATION: setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE)); break; case SEARCH: setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE)); break; case SENSOR: setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE)); break; case STORAGE: setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE)); break; case WALLPAPER: setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE)); break; case VIBRATOR: setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE)); break; case CONNECT: setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE)); break; case NETWORK_STATUS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE)); } break; case WIFI: setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE)); break; case AUDIO: setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE)); break; case FP: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE)); } break; case MEDIA_ROUTER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE)); } break; case SUB: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE)); } break; case IME: setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE)); break; case CLIP_BOARD: setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE)); break; case APP_WIDGET: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE)); } break; case DEVICE_POLICY: setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE)); break; case DOWNLOAD: setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE)); break; case BATTERY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE)); } break; case NFC: setField(field, forWho, context.getSystemService(Context.NFC_SERVICE)); break; case DISPLAY: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE)); } break; case USER: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { setField(field, forWho, context.getSystemService(Context.USER_SERVICE)); } break; case APP_OPS: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE)); } break; case BITMAP: setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null)); break; } }
From source file:com.android.screenspeak.controller.FullScreenReadControllerApp.java
@SuppressWarnings("deprecation") public FullScreenReadControllerApp(FeedbackController feedbackController, CursorController cursorController, ScreenSpeakService service) {//w w w . j ava2s . c o m if (cursorController == null) throw new IllegalStateException(); if (feedbackController == null) throw new IllegalStateException(); mCursorController = cursorController; mFeedbackController = feedbackController; mService = service; mWakeLock = ((PowerManager) service.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); }
From source file:com.google.android.marvin.talkback.ProcessorVolumeStream.java
@SuppressWarnings("deprecation") public ProcessorVolumeStream(TalkBackService service) { mContext = service;/*from w w w . j a v a2s. c o m*/ mAudioManager = (AudioManager) service.getSystemService(Context.AUDIO_SERVICE); mCursorController = service.getCursorController(); mFeedbackController = service.getFeedbackController(); mLongPressHandler = new LongPressHandler(this); final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, WL_TAG); }
From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java
/** * Called when a local notification broad cast is received. Funnels the notification * into the app if open or into the notification bar if not * //from w w w .j a v a2s . c om * @author Steven Hendrie * * @param The context. * @param The intent. */ @SuppressWarnings("deprecation") @Override public void onReceive(Context in_context, Intent in_intent) { //evaluate whether or not the main engine activity is in the foreground boolean isAppInForeground = false; if (CSApplication.get() != null && CSApplication.get().isActive() == true) { isAppInForeground = true; } //if the main engine activity is in the foreground, simply pass the //notification into it. Otherwise display a notification. if (isAppInForeground == true) { final Intent intent = new Intent(in_intent.getAction()); Bundle mapParams = in_intent.getExtras(); Iterator<String> iter = mapParams.keySet().iterator(); while (iter.hasNext()) { String strKey = iter.next(); intent.putExtra(strKey, mapParams.get(strKey).toString()); } LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication .get().getSystem(LocalNotificationNativeInterface.InterfaceID); if (localNotificationNI != null) { localNotificationNI.onNotificationReceived(intent); } } else { //aquire a wake lock if (s_wakeLock != null) { s_wakeLock.release(); } PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE); s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock"); s_wakeLock.acquire(); //pull out the information from the intent Bundle params = in_intent.getExtras(); CharSequence title = params.getString(k_paramNameTitle); CharSequence text = params.getString(k_paramNameBody); int intentId = params.getInt(LocalNotification.k_paramNameNotificationId); int paramSize = params.size(); String[] keys = new String[paramSize]; String[] values = new String[paramSize]; Iterator<String> iter = params.keySet().iterator(); int paramNumber = 0; while (iter.hasNext()) { keys[paramNumber] = iter.next(); values[paramNumber] = params.get(keys[paramNumber]).toString(); ++paramNumber; } Intent openAppIntent = new Intent(in_context, CSActivity.class); openAppIntent.setAction("android.intent.action.MAIN"); openAppIntent.addCategory("android.intent.category.LAUNCHER"); openAppIntent.putExtra(k_appOpenedFromNotification, true); openAppIntent.putExtra(k_arrayOfKeysName, keys); openAppIntent.putExtra(k_arrayOfValuesName, values); openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIconBitmap = null; int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large"); //Use small icon if no large icon if (LargeIconID == 0) { LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"); } if (LargeIconID > 0) { largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID); } Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title) .setContentText(text) .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify")) .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build(); NotificationManager notificationManager = (NotificationManager) in_context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(intentId, notification); Toast.makeText(in_context, text, Toast.LENGTH_LONG).show(); } }
From source file:com.android.talkback.controller.FullScreenReadControllerApp.java
@SuppressWarnings("deprecation") public FullScreenReadControllerApp(FeedbackController feedbackController, CursorController cursorController, TalkBackService service) {/*from w w w.ja v a 2s . c om*/ if (cursorController == null) throw new IllegalStateException(); if (feedbackController == null) throw new IllegalStateException(); mCursorController = cursorController; mFeedbackController = feedbackController; mService = service; mWakeLock = ((PowerManager) service.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); }
From source file:com.lchtime.safetyexpress.ui.chat.hx.activity.ContactActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { String packageName = getPackageName(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); if (!pm.isIgnoringBatteryOptimizations(packageName)) { Intent intent = new Intent(); intent.setAction(android.provider.Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + packageName)); startActivity(intent);/*from w w w. j av a 2s .com*/ } } //make sure activity will not in background if user is logged into another device or removed if (savedInstanceState != null && savedInstanceState.getBoolean(Constant.ACCOUNT_REMOVED, false)) { DemoHelper.getInstance().logout(false, null); finish(); startActivity(new Intent(this, LoginUI.class)); return; } else if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) { finish(); startActivity(new Intent(this, LoginUI.class)); return; } setContentView(R.layout.em_activity_main); // runtime permission for android 6.0, just require all permissions here for simple requestPermissions(); initView(); showExceptionDialogFromIntent(getIntent()); inviteMessgeDao = new InviteMessgeDao(this); UserDao userDao = new UserDao(this); contactListFragment = new ContactListFragment(); currentTabIndex = 1; getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, contactListFragment) .show(contactListFragment).commit(); //register broadcast receiver to receive the change of group from DemoHelper registerBroadcastReceiver(); EMClient.getInstance().contactManager().setContactListener(new MyContactListener()); //debug purpose only registerInternalDebugReceiver(); }
From source file:com.google.android.marvin.mytalkback.FullScreenReadController.java
@SuppressWarnings("deprecation") public FullScreenReadController(TalkBackService service) { mService = service;//from w w w . j a va 2 s. co m mSpeechController = service.getSpeechController(); mCursorController = service.getCursorController(); mFeedbackController = MappedFeedbackController.getInstance(); final PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); setReadingState(AutomaticReadingState.STOPPED); }