List of usage examples for android.os PowerManager FULL_WAKE_LOCK
int FULL_WAKE_LOCK
To view the source code for android.os PowerManager FULL_WAKE_LOCK.
Click Source Link
From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearKeyEventProfileActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TouchWakelockTag"); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (!mWakeLock.isHeld()) { mWakeLock.acquire();/* w ww .j a v a 2 s . c o m*/ } setRegisterEvent(getIntent()); setContentView(R.layout.activity_wear_keyevent_profile); WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(final WatchViewStub stub) { mBtnKeyMode = (Button) stub.findViewById(R.id.button_key_mode); mBtnKeyMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { // Update Key Mode. mKeyMode++; if (mKeyMode >= KM_MAX_CNT) { mKeyMode = KM_STD_KEY; } String keyMode; switch (mKeyMode) { case KM_MEDIA_CTRL: keyMode = getString(R.string.key_mode_media_ctrl); break; case KM_DPAD_BUTTON: keyMode = getString(R.string.key_mode_dpad_button); break; case KM_USER: keyMode = getString(R.string.key_mode_user); break; case KM_STD_KEY: default: keyMode = getString(R.string.key_mode_std_key); break; } mBtnKeyMode.setText(keyMode); } }); mBtnCancel = (Button) stub.findViewById(R.id.button_cancel); mBtnCancel.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: sendMessageData(action, KEYCODE_CANCEL); break; default: break; } return false; } }); mBtnOk = (Button) stub.findViewById(R.id.button_ok); mBtnOk.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: sendMessageData(action, KEYCODE_OK); break; default: break; } return false; } }); } }); Intent i = new Intent(WearConst.ACTION_WEAR_PING_SERVICE); LocalBroadcastManager.getInstance(this).sendBroadcast(i); }
From source file:com.thebigbang.ftpclient.FTPOperation.java
/** * will force keep the device turned on for all the operation duration. * @param params// ww w. j a va2s . com * @return */ @SuppressLint("Wakelock") @SuppressWarnings("deprecation") @Override protected Boolean doInBackground(FTPBundle... params) { Thread.currentThread().setName("FTPOperationWorker"); for (final FTPBundle bundle : params) { FTPClient ftp = new FTPClient(); PowerManager pw = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE); WakeLock w = pw.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FTP Client"); try { // setup ftp connection: InetAddress addr = InetAddress.getByName(bundle.FTPServerHost); //set here the timeout. TimeoutThread timeout = new TimeoutThread(_timeOut, new FTPTimeout() { @Override public void Occurred(TimeoutException e) { bundle.Exception = e; bundle.OperationStatus = FTPOperationStatus.Failed; publishProgress(bundle); } }); timeout.start(); ftp.connect(addr, bundle.FTPServerPort); int reply = ftp.getReplyCode(); timeout.Stop(); if (!FTPReply.isPositiveCompletion(reply)) { throw new IOException("connection refuse"); } ftp.login(bundle.FTPCredentialUsername, bundle.FTPCredentialPassword); if (bundle.OperationType == FTPOperationType.Connect) { bundle.OperationStatus = FTPOperationStatus.Succed; publishProgress(bundle); continue; } ftp.setFileType(FTP.BINARY_FILE_TYPE); ftp.enterLocalPassiveMode(); w.acquire(); // then switch between enum of operation types. if (bundle.OperationType == FTPOperationType.RetrieveFilesFoldersList) { ftp.changeWorkingDirectory(bundle.RemoteWorkingDirectory); bundle.FilesOnCurrentPath = ftp.listFiles(); bundle.FoldersOnCurrentPath = ftp.listDirectories(); bundle.OperationStatus = FTPOperationStatus.Succed; } else if (bundle.OperationType == FTPOperationType.RetrieveFolderList) { ftp.changeWorkingDirectory(bundle.RemoteWorkingDirectory); bundle.FoldersOnCurrentPath = ftp.listDirectories(); bundle.OperationStatus = FTPOperationStatus.Succed; } else if (bundle.OperationType == FTPOperationType.RetrieveFileList) { ftp.changeWorkingDirectory(bundle.RemoteWorkingDirectory); bundle.FilesOnCurrentPath = ftp.listFiles(); bundle.OperationStatus = FTPOperationStatus.Succed; } else if (bundle.OperationType == FTPOperationType.GetData) { String finalFPFi = bundle.LocalFilePathName; // The remote filename to be downloaded. if (bundle.LocalWorkingDirectory != null && bundle.LocalWorkingDirectory != "") { File f = new File(bundle.LocalWorkingDirectory); f.mkdirs(); finalFPFi = bundle.LocalWorkingDirectory + finalFPFi; } FileOutputStream fos = new FileOutputStream(finalFPFi); // Download file from FTP server String finalFileN = bundle.RemoteFilePathName; if (bundle.RemoteWorkingDirectory != null && bundle.RemoteWorkingDirectory != "") { finalFileN = bundle.RemoteWorkingDirectory + finalFileN; } boolean b = ftp.retrieveFile(finalFileN, fos); if (b) bundle.OperationStatus = FTPOperationStatus.Succed; else bundle.OperationStatus = FTPOperationStatus.Failed; fos.close(); } else if (bundle.OperationType == FTPOperationType.SendData) { InputStream istr = new FileInputStream(bundle.LocalFilePathName); ftp.changeWorkingDirectory(bundle.RemoteWorkingDirectory); Boolean b = ftp.storeFile(bundle.RemoteFilePathName, istr); istr.close(); if (b) bundle.OperationStatus = FTPOperationStatus.Succed; else bundle.OperationStatus = FTPOperationStatus.Failed; } else if (bundle.OperationType == FTPOperationType.DeleteData) { throw new IOException("DeleteData is Not yet implemented"); } ftp.disconnect(); // then finish/return. //publishProgress(bundle); } catch (IOException e) { e.printStackTrace(); bundle.Exception = e; bundle.OperationStatus = FTPOperationStatus.Failed; } try { w.release(); } catch (RuntimeException ex) { ex.printStackTrace(); } publishProgress(bundle); } return true; }
From source file:com.konsula.app.gcm.MyGcmListenerService.java
/** * Called when message is received./*www. j a va2s . c o m*/ * * @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"); togo = data.getString("type"); bundle = data; // Settings.System.putString(this.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, message); Log.d(TAG, String.valueOf(data)); Log.d(TAG, "Message: " + message); if (from.startsWith("/topics/")) { // message received from some topic. } else { // normal downstream message. } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); wl.acquire(3000); wl.release(); //kalo misalnya app kebuka, message diterima disini. // [START_EXCLUDE] /** * Production applications would usually process the message here. * Eg: - Syncing with server. * - Store message in local database. * - Update UI. */ /** * In some cases it may be useful to show a notification indicating to the user * that a message was received. */ handleGCM(bundle); sendNotification(message); // [END_EXCLUDE] }
From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java
/** * Turns the screen on./*from ww w. j av a 2s.c o m*/ */ private void screenOn() { if (screenOffLock == null || !screenOffLock.isHeld()) { return; } logger.debug("Release lock"); screenOffLock.release(); PowerManager pm = JitsiApplication.getPowerManager(); PowerManager.WakeLock onLock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "full_on"); onLock.acquire(); if (onLock.isHeld()) { onLock.release(); } }
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 ww . j a v a 2s . co m * 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.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 * /*ww w .ja v a 2s . com*/ * @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:net.kseek.camtest.ui.CamtestActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApplication = (CamtestApplication) getApplication(); setContentView(R.layout.camtest);/*w ww . j av a2 s. 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: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();/*ww w. java2 s . co m*/ // 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:org.android.gcm.client.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { final SharedPreferences prefs = getSharedPreferences("gcmclient", Context.MODE_PRIVATE); pushpak = prefs.getString("push_pak", ""); pushact = prefs.getString("push_act", ""); final boolean pushon = prefs.getBoolean("push_on", true); final boolean pushnotif = prefs.getBoolean("push_notification", true); if (pushnotif) { final String notifact = prefs.getString("notification_act", ""); Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // Send a notification. if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*// w w w . j a v a 2s. co m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification(getString(R.string.send_error) + ": " + extras.toString(), notifact); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification(getString(R.string.deleted) + ": " + extras.toString(), notifact); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. sendNotification( getString(R.string.received, extras.getString("name"), extras.getString("num")), notifact); Log.i(TAG, "Received: " + extras.toString()); } } } // End if push is not enabled. if (!pushon) { // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); return; } final boolean fullwake = prefs.getBoolean("full_wake", false); final boolean endoff = prefs.getBoolean("end_off", true); // Manage the screen. PowerManager mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = mPowerManager .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); boolean misScreenOn = mPowerManager.isScreenOn(); int mScreenTimeout = 0; if (!misScreenOn) { if (endoff) { // Change the screen timeout setting. mScreenTimeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0); if (mScreenTimeout != 0) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 3000); } } // Full wake lock if (fullwake) { mWakeLock.acquire(); } } // Start the activity. try { startActivity(getPushactIntent(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)); // Wait to register. Thread.sleep(REGISTER_DURATION); } catch (android.content.ActivityNotFoundException e) { RING_DURATION = 0; Log.i(TAG, "Activity not started"); } catch (InterruptedException e) { } // Release the wake lock. if (!misScreenOn && fullwake) { mWakeLock.release(); } GcmBroadcastReceiver.completeWakefulIntent(intent); // Restore the screen timeout setting. if (endoff && mScreenTimeout != 0) { try { Thread.sleep(RING_DURATION); } catch (InterruptedException e) { } Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, mScreenTimeout); } }
From source file:com.android.switchaccess.SwitchAccessService.java
@SuppressWarnings("deprecation") @Override/*from w w w . j a va2 s . c om*/ protected void onServiceConnected() { sInstance = this; mOverlayController = new OverlayController(new SimpleOverlay(this)); mOverlayController.configureOverlay(); mOptionManager = new OptionManager(mOverlayController); mMainTreeBuilder = new MainTreeBuilder(this); mAutoScanController = new AutoScanController(mOptionManager, new Handler(), this); mKeyboardEventManager = new KeyboardEventManager(this, mOptionManager, mAutoScanController); mAnalytics = new Analytics(); mAnalytics.start(); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "SwitchAccess"); SharedPreferencesUtils.getSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); mActionProcessor = new ActionProcessor(this); mEventProcessor = new UiChangeDetector(mActionProcessor); }