List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:com.gecq.musicwave.player.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "music wave headset button"); mWakeLock.setReferenceCounted(false); }/* w w w. j a v a2 s . c o m*/ if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.cyanogenmod.eleven.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Eleven headset button"); mWakeLock.setReferenceCounted(false); }/*from ww w . j a va2s . c o m*/ if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.andrew.apollo.MediaButtonIntentReceiver.java
private static void acquireWakeLockAndSendMessage(Context context, Message msg, long delay) { if (mWakeLock == null) { Context appContext = context.getApplicationContext(); PowerManager pm = (PowerManager) appContext.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Apollo headset button"); mWakeLock.setReferenceCounted(false); }//from w ww.j a v a2 s . c om if (DEBUG) Log.v(TAG, "Acquiring wake lock and sending " + msg.what); // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateNotification(Context context, String message) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); notificationIntent.putExtra("alert", message); message = message + " would like to add you as friend"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire();/*from w w w . ja v a 2s .com*/ // 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.frygo.findmybuddy.GCMIntentService.java
private static void generateAcceptfriendNotification(Context context, String message, String status) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); if (status.equalsIgnoreCase("accept")) message = message + " added you as buddy"; else// ww w. j ava 2s . c om message = message + " rejected you as buddy"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); 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:com.google.android.gcm.GCMBaseIntentService.java
/** * Called from the broadcast receiver./*from www .jav a 2s . c o m*/ * <p> * Will process the received intent, call handleMessage(), registered(), * etc. in background threads, with a wake lock, while keeping the service * alive. */ static void runIntentInService(Context context, Intent intent, String className) { synchronized (LOCK) { if (sWakeLock == null) { // This is called from BroadcastReceiver, there is no init. PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); sWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_KEY); } } Log.v(TAG, "Acquiring wakelock"); sWakeLock.acquire(); intent.setClassName(context, className); context.startService(intent); }
From source file:com.groundupworks.wings.core.WingsService.java
/** * Acquires a wake lock./*from w w w . j a va 2s .c o m*/ * * @param context the {@link Context}. */ private synchronized static void acquireWakeLock(Context context) { // Setup wake lock. if (sWakeLock == null) { PowerManager powerManager = (PowerManager) context.getApplicationContext() .getSystemService(Context.POWER_SERVICE); sWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, NAME); sWakeLock.setReferenceCounted(true); } // Acquire lock. sWakeLock.acquire(); sLogger.log(WingsService.class, "acquireWakeLock", "sWakeLock=" + sWakeLock); }
From source file:com.entertailion.android.slideshow.utils.Utils.java
/** * Prevent the screensave from activating on Google TV devices. * /*from w w w.j a va2s . c o m*/ * @param context */ public static void wakeUp(Context context) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "tag"); wl.acquire(); wl.release(); }
From source file:fr.inria.ucn.Helpers.java
/** * Acquire the wakelock to keep the CPU running. * @param c/*from w ww. j a v a 2 s . c om*/ */ public static synchronized void acquireLock(Context c) { PowerManager mgr = (PowerManager) c.getSystemService(Context.POWER_SERVICE); if (lock == null) { lock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.CPU_WAKE_LOCK); lock.setReferenceCounted(true); } Log.d(Constants.LOGTAG, "acquire lock"); lock.acquire(); }
From source file:me.myatminsoe.myansms.SmsReceiver.java
static void handleOnReceive(final BroadcastReceiver receiver, final Context context, final Intent intent) { final String action = intent.getAction(); final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakelock.acquire();// w w w .j ava 2s. co m try { Thread.sleep(SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } String t = null; if (SenderActivity.MESSAGE_SENT_ACTION.equals(action)) { handleSent(context, intent, receiver.getResultCode()); } else { boolean silent = false; if (ACTION_SMS_OLD.equals(action) || ACTION_SMS_NEW.equals(action)) { Bundle b = intent.getExtras(); assert b != null; Object[] messages = (Object[]) b.get("pdus"); SmsMessage[] smsMessage = new SmsMessage[messages.length]; int l = messages.length; for (int i = 0; i < l; i++) { smsMessage[i] = SmsMessage.createFromPdu((byte[]) messages[i]); } t = null; if (l > 0) { // concatenate multipart SMS body StringBuilder sbt = new StringBuilder(); for (int i = 0; i < l; i++) { sbt.append(smsMessage[i].getMessageBody()); } t = sbt.toString(); // ! Check in blacklist db - filter spam String s = smsMessage[0].getDisplayOriginatingAddress(); // this code is used to strip a forwarding agent and display the orginated number as sender final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (prefs.getBoolean(PreferencesActivity.PREFS_FORWARD_SMS_CLEAN, false) && t.contains(":")) { Pattern smsPattern = Pattern.compile("([0-9a-zA-Z+]+):"); Matcher m = smsPattern.matcher(t); if (m.find()) { s = m.group(1); // now strip the sender from the message Pattern textPattern = Pattern.compile("^[0-9a-zA-Z+]+: (.*)"); Matcher m2 = textPattern.matcher(t); if (t.contains(":") && m2.find()) { t = m2.group(1); Log.d(TAG, "stripped the message"); } } } final SpamDB db = new SpamDB(context); db.open(); if (db.isInDB(smsMessage[0].getOriginatingAddress())) { silent = true; } db.close(); if (action.equals(ACTION_SMS_NEW)) { // API19+: save message to the database ContentValues values = new ContentValues(); values.put("address", s); values.put("body", t); context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values); } } } else if (ACTION_MMS_OLD.equals(action) || ACTION_MMS_MEW.equals(action)) { t = MMS_BODY; // TODO API19+ MMS code } if (!silent) { int count = MAX_SPINS; do { try { Thread.sleep(SLEEP); } catch (InterruptedException e) { e.printStackTrace(); } --count; } while (updateNewMessageNotification(context, t) <= 0 && count > 0); if (count == 0) { // use messages as they are available updateNewMessageNotification(context, null); } } } wakelock.release(); Log.i(TAG, "wakelock released"); }