List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:ti.modules.titanium.android.notificationmanager.NotificationManagerModule.java
@Kroll.method public void notify(int id, Object notificationValue) { NotificationProxy notificationProxy = NotificationProxy.fromObject(notificationValue); NotificationManager manager = getManager(); if (manager != null && notificationProxy != null) { // targeting Android O or above? create default channel try {/* ww w.j a va2s . c o m*/ notificationProxy.setCurrentId(id); Notification notification = notificationProxy.getNotification(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notification.getChannelId() == DEFAULT_CHANNEL_ID) { useDefaultChannel(); } getManager().notify(id, notification); HashMap wakeParams = notificationProxy.getWakeParams(); if (wakeParams != null) { int wakeTime = TiConvert.toInt(wakeParams.get("time"), 3000); int wakeFlags = TiConvert.toInt(wakeParams.get("flags"), (PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE)); PowerManager pm = (PowerManager) TiApplication.getInstance() .getSystemService(TiApplication.getInstance().getApplicationContext().POWER_SERVICE); if (pm != null && !pm.isScreenOn()) { try { WakeLock wl = pm.newWakeLock(wakeFlags, "TiWakeLock"); wl.acquire(wakeTime); } catch (IllegalArgumentException e) { Log.e(TAG, e.getMessage()); } } } } catch (Exception e) { } } }
From source file:net.micode.soundrecorder.RecorderService.java
@Override public void onCreate() { super.onCreate(); mRecorder = null;// w w w . ja v a 2s . c om mLowStorageNotification = null; mRemainingTimeCalculator = new RemainingTimeCalculator(); mNeedUpdateRemainingTime = false; mNotifiManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SoundRecorder"); mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); mAudioSampleRate = Integer .parseInt(settings.getString("p_audio_samplerate", Constants.DEFAULT_AUDIO_SAMPLE_RATE)); }
From source file:com.daiv.android.twitter.utils.NotificationUtils.java
public static void makeFavsNotification(ArrayList<String[]> tweets, Context context, boolean toDrawer) { String shortText;//from www . j a va2s . co m String longText; String title; int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon; PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, null, 0); NotificationCompat.InboxStyle inbox = null; if (tweets.size() == 1) { title = tweets.get(0)[0]; shortText = tweets.get(0)[1]; longText = shortText; largeIcon = getImage(context, tweets.get(0)[2]); } else { inbox = new NotificationCompat.InboxStyle(); title = context.getResources().getString(R.string.favorite_users); shortText = tweets.size() + " " + context.getResources().getString(R.string.fav_user_tweets); longText = ""; try { inbox.setBigContentTitle(shortText); } catch (Exception e) { } if (tweets.size() <= 5) { for (String[] s : tweets) { inbox.addLine(Html.fromHtml("<b>" + s[0] + ":</b> " + s[1])); } } else { for (int i = 0; i < 5; i++) { inbox.addLine(Html.fromHtml("<b>" + tweets.get(i)[0] + ":</b> " + tweets.get(i)[1])); } inbox.setSummaryText("+" + (tweets.size() - 5) + " " + context.getString(R.string.tweets)); } largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } NotificationCompat.Builder mBuilder; AppSettings settings = AppSettings.getInstance(context); if (shortText.contains("@" + settings.myScreenName)) { // return because there is a mention notification for this already return; } Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(shortText, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (inbox == null) { mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText))); } else { mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(2, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.daiv.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, shortText); } // Light Flow notification sendToLightFlow(context, title, shortText); } }
From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java
@Override protected void onHandleIntent(Intent intent) { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AlarmReceiver"); wakeLock.acquire();//from w w w. j a va 2 s .c om try { fireAlarm(intent); } catch (Exception e) { Crashlytics.logException(e); } wakeLock.release(); if (NotificationPopup.instance != null && Prefs.showNotificationScreen()) { NotificationPopup.instance.finish(); } Times.setAlarms(); }
From source file:at.tugraz.ist.akm.webservice.server.SimpleWebServer.java
public SimpleWebServer(Context context, WebserverProtocolConfig serverConfig, IHttpAccessCallback callback) throws Exception { mHttpAuthCallback = callback;/*from w w w .j av a 2 s.c o m*/ mContext = context; PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); WifiIpAddress wifiAddressReader = new WifiIpAddress(context); mSocketAddress = InetAddress.getByName(wifiAddressReader.readLocalIpAddress()); wifiAddressReader.close(); wifiAddressReader = null; setNewServerConfiguration(serverConfig); mLog.debug("building server for [" + mServerConfig.protocolName + "://" + mSocketAddress + ":" + mServerConfig.port + "]"); readRequestHandlers(); readRequestInterceptors(); }
From source file:cm.aptoide.pt.DownloadQueueService.java
@Override public void onCreate() { super.onCreate(); notifications = new HashMap<Integer, HashMap<String, String>>(); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); keepScreenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power"); Log.d("Aptoide-DowloadQueueService", "Created"); }
From source file:com.mishiranu.dashchan.content.service.AudioPlayerService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//www . j a v a2s. c o m public void onCreate() { super.onCreate(); audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); int notificationColor = 0; if (C.API_LOLLIPOP) { Context themedContext = new ContextThemeWrapper(this, Preferences.getThemeResource()); notificationColor = ResourceUtils.getColor(themedContext, android.R.attr.colorAccent); } this.notificationColor = notificationColor; PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AudioPlayerWakeLock"); wakeLock.setReferenceCounted(false); context = new ContextThemeWrapper(this, R.style.Theme_Special_Notification); }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///www .j a v a 2s .c om private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:net.kseek.camtest.ui.CamtestActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApplication = (CamtestApplication) getApplication(); setContentView(R.layout.camtest);/*from w ww . ja v a 2s. c o m*/ if (findViewById(R.id.handset_pager) != null) { // Handset detected ! mAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.handset_pager); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); mSurfaceView = (SurfaceView) findViewById(R.id.handset_camera_view); SessionBuilder.getInstance().setSurfaceView(mSurfaceView); SessionBuilder.getInstance().setPreviewOrientation(90); } else { // Tablet detected ! device = TABLET; mAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.tablet_pager); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); SessionBuilder.getInstance().setPreviewOrientation(0); } mViewPager.setAdapter(mAdapter); // Prevents the phone from going to sleep mode PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "net.kseek.camtest.wakelock"); // Starts the service of the HTTP server this.startService(new Intent(this, CustomHttpServer.class)); // Starts the service of the RTSP server this.startService(new Intent(this, CustomRtspServer.class)); }
From source file:org.secu3.android.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { setTheme(PreferenceManager.getDefaultSharedPreferences(this) .getBoolean(getString(R.string.pref_night_mode_key), false) ? R.style.AppBaseTheme : R.style.AppBaseTheme_Light); setContentView(R.layout.activity_main); packetUtils = new PacketUtils(this); sensorsFormat = getString(R.string.sensors_format); speedFormat = getString(R.string.speed_format); sensorsRawFormat = getString(R.string.sensors_raw_format); textViewData = (TextView) findViewById(R.id.textViewData); textViewDataExt = (TextView) findViewById(R.id.textViewDataExt); textViewStatus = (TextView) findViewById(R.id.mainTextViewStatus); textFWInfo = (TextView) findViewById(R.id.mainTextFWInfo); receiver = new ReceiveMessages(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Secu3Droid wakelock"); if (savedInstanceState != null) { textViewData.setText(savedInstanceState.getString(DATA)); textViewStatus.setText(savedInstanceState.getString(STATUS)); rawSensors = savedInstanceState.getBoolean(RAW_SENSORS); }// w ww . j a v a2 s . c o m setRawMode(rawSensors); logButtonLayout = (LinearLayout) findViewById(R.id.mainLogButtonLayout); View.OnClickListener logButtonListener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.mainLogButton1: startService(new Intent(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK, Uri.EMPTY, v.getContext(), Secu3Service.class).putExtra(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK_PARAM, SECU3_TASK.SECU3_SET_LOG_MARKER_1.ordinal())); break; case R.id.mainLogButton2: startService(new Intent(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK, Uri.EMPTY, v.getContext(), Secu3Service.class).putExtra(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK_PARAM, SECU3_TASK.SECU3_SET_LOG_MARKER_2.ordinal())); break; case R.id.mainLogButton3: startService(new Intent(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK, Uri.EMPTY, v.getContext(), Secu3Service.class).putExtra(Secu3Service.ACTION_SECU3_SERVICE_SET_TASK_PARAM, SECU3_TASK.SECU3_SET_LOG_MARKER_3.ordinal())); break; default: break; } } }; Button b = (Button) findViewById(R.id.mainLogButton1); b.setOnClickListener(logButtonListener); b = (Button) findViewById(R.id.mainLogButton2); b.setOnClickListener(logButtonListener); b = (Button) findViewById(R.id.mainLogButton3); b.setOnClickListener(logButtonListener); super.onCreate(savedInstanceState); }