List of usage examples for android.os PowerManager newWakeLock
public WakeLock newWakeLock(int levelAndFlags, String tag)
From source file:com.TwentyCodes.android.IOIOTruck.CameraActivity.java
/** * Called when the activity is resuming/*from ww w . j av a 2 s. c o m*/ * (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onResume() */ @Override protected void onResume() { PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, TAG); mWakeLock.acquire(); super.onResume(); }
From source file:com.andreadec.musicplayer.IndexFolderService.java
@Override protected void onHandleIntent(Intent intent) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "IndexFolderService"); wakeLock.acquire();/* www .j a v a 2 s . c o m*/ try { SongsDatabase songsDatabase = new SongsDatabase(); db = songsDatabase.getWritableDatabase(); File folder = new File(intent.getStringExtra("folder")); clearSongsDatabase(); index(folder); db.close(); } catch (Exception e) { } // Just to be sure the wake lock is always released, also if something wrong happens. wakeLock.release(); }
From source file:com.endiansoftware.echo.remotewatch.GcmIntentService.java
private void sendNotification(Bundle msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(msg.get("key1").toString()) .setContentText(msg.get("key2").toString()).setTicker(msg.get("key1").toString()); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); if (msg.get("collapse_key").toString().equals("Emergency")) { notification.flags |= notification.FLAG_INSISTENT | notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L, 100L, 200L, 500L }; } else {/*from ww w . j ava 2 s .c om*/ notification.flags |= notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L }; } mNotificationManager.notify(NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(); }
From source file:com.samknows.measurement.MainService.java
public void onBegin() { synchronized (sync) { isExecuting = true;//from w w w . j a v a 2s .co m } // obtain wake lock, other way our service may stop executing PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MainService.class.getName()); wakeLock.acquire(); // reschedule service in the beginning to ensure it will be started if // killed. OtherUtils.rescheduleRTC(this, appSettings.rescheduleServiceTime); collector.start(); }
From source file:it.evilsocket.dsploit.core.System.java
public static void init(Context context) throws Exception { mContext = context;//www .j a v a 2 s . com try { mStoragePath = getSettings().getString("PREF_SAVE_PATH", Environment.getExternalStorageDirectory().toString()); mSessionName = "dsploit-session-" + java.lang.System.currentTimeMillis(); mUpdateManager = new UpdateManager(mContext); mPlugins = new ArrayList<Plugin>(); mTargets = new Vector<Target>(); mOpenPorts = new SparseIntArray(3); // if we are here, network initialization didn't throw any error, lock wifi WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiLock == null) mWifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "wifiLock"); if (mWifiLock.isHeld() == false) mWifiLock.acquire(); // wake lock if enabled if (getSettings().getBoolean("PREF_WAKE_LOCK", true) == true) { PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (mWakeLock == null) mWakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "wakeLock"); if (mWakeLock.isHeld() == false) mWakeLock.acquire(); } // set ports try { HTTP_PROXY_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_PROXY_PORT", "8080")); HTTP_SERVER_PORT = Integer.parseInt(getSettings().getString("PREF_HTTP_SERVER_PORT", "8081")); HTTPS_REDIR_PORT = Integer.parseInt(getSettings().getString("PREF_HTTPS_REDIRECTOR_PORT", "8082")); } catch (NumberFormatException e) { HTTP_PROXY_PORT = 8080; HTTP_SERVER_PORT = 8081; HTTPS_REDIR_PORT = 8082; } mNmap = new NMap(mContext); mArpSpoof = new ArpSpoof(mContext); mEttercap = new Ettercap(mContext); mIptables = new IPTables(); mHydra = new Hydra(mContext); mTcpdump = new TcpDump(mContext); // initialize network data at the end mNetwork = new Network(mContext); Target network = new Target(mNetwork), gateway = new Target(mNetwork.getGatewayAddress(), mNetwork.getGatewayHardware()), device = new Target(mNetwork.getLocalAddress(), mNetwork.getLocalHardware()); gateway.setAlias(mNetwork.getSSID()); device.setAlias(android.os.Build.MODEL); mTargets.add(network); mTargets.add(gateway); mTargets.add(device); mInitialized = true; } catch (Exception e) { errorLogging(TAG, e); throw e; } }
From source file:me.postar.postarv2.LocalService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Functions.getParcels(parcels, this); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Postar"); if (Functions.isConnectedToInternet(LocalService.this)) { Ion.with(this).load("GET", "https://e-racuni.postacg.me/PracenjePosiljaka/").asString().withResponse() .setCallback(new FutureCallback<Response<String>>() { @Override//from w w w . ja v a 2 s . c om public void onCompleted(Exception e, Response<String> result) { Document html = Jsoup.parse(result.getResult()); Element viewState = html.getElementById("__VIEWSTATE"); Element eventValidation = html.getElementById("__EVENTVALIDATION"); Element btnPronadji = html.getElementById("btnPronadji"); for (final PostParcel parcel : parcels) { if (parcel.isAlarmOn()) { Ion.with(LocalService.this) .load("POST", "https://e-racuni.postacg.me/PracenjePosiljaka/") .setBodyParameter("__VIEWSTATE", viewState.val()) .setBodyParameter("__EVENTVALIDATION", eventValidation.val()) .setBodyParameter("btnPronadji", btnPronadji.val()) .setBodyParameter("txtPrijemniBroj", parcel.getParcelNo()).asString() .withResponse().setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, final Response<String> result) { Document html = Jsoup.parse(result.getResult()); Element table = html.getElementById("dgInfo"); if (table != null) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( LocalService.this) .setSmallIcon(R.drawable.ic_mail_outline) .setLargeIcon(BitmapFactory.decodeResource( getResources(), R.drawable.ic_mail_outline)) .setAutoCancel(true); mBuilder.setContentTitle(getString(R.string.message_title)); mBuilder.setContentText( getString(R.string.message_content)); Intent activityIntent = new Intent(LocalService.this, StatusActivity.class); activityIntent.putExtra("parcel", parcel); PendingIntent resultPendingIntent = PendingIntent .getActivity(LocalService.this, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); stopSelf(); wl.release(); } } }); } } } }); } return START_NOT_STICKY; }
From source file:org.jitsi.android.gui.fragment.ProximitySensorFragment.java
/** * Turns the screen on./* w w w . j a v a2 s .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:ca.lightseed.winston.WinstonService.java
/** * Creates the partial wake-lock which keeps CPU running, and allows this service * to continue passing location data even with screen off. * NOTE: WakeLocks consume battery very quickly. *//*from w w w . j av a2s. c o m*/ @Override public void onCreate() { super.onCreate(); PowerManager pm = (PowerManager) getSystemService(this.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DoNotSleep"); // TODO: Intrusively many toasts are generated. Fine for testing, not fine for release. Toast.makeText(this, "Created Winston tracking service", Toast.LENGTH_SHORT).show(); }
From source file:ws.logv.trainmonitor.GCMIntentService.java
@Override protected void onMessage(final Context context, Intent intent) { if (intent.hasExtra("command")) { String command = intent.getStringExtra("command"); if ("sync".equals(command)) { String type = intent.getStringExtra("type"); if ("subscription".equals(type)) { Workflow.getEventBus(context).post(new PullSubscriptionsEvent()); }/*w ww . j ava 2 s .co m*/ } } else { String train = intent.getStringExtra("train"); if (wl == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Refresh trains"); } wl.acquire(2000); EventBus bus = Workflow.getEventBus(context); bus.register(this, FetchTrainDetailsResult.class); bus.post(new FetchTrainDetailsCommand(train)); } }
From source file:com.mobile.lapa.waitandsee.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param title//w w w .ja v a2 s . c o m * @param message GCM message received. */ private void sendNotification(String title, String message) { Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("TITLE_KEY", title); intent.putExtra("MESSAGE_KEY", message); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.game_finished); //Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.sap_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Random random = new Random(); // int notificationId = random.nextInt(9999 - 1000) + 1000; notificationManager.notify(0 /*notificationId*/, notificationBuilder.build()); // -------- Wake up the phone and show the main activity PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = pm.newWakeLock( (PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MainServiceTag"); mWakeLock.acquire(); // ------- Send notification to the android system startActivity(intent); mWakeLock.release(); }