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.vurtex.wakeup.activity.MainActivity.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 setContentView(R.layout.activity_main); initView(); conversationListFragment = new Item1Fragment(); contactListFragment = new Item1Fragment(); Fragment settingFragment = new Item1Fragment(); fragments = new Fragment[] { conversationListFragment, contactListFragment, settingFragment }; getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, conversationListFragment) .add(R.id.fragment_container, contactListFragment).hide(contactListFragment) .show(conversationListFragment).commit(); //register broadcast receiver to receive the change }
From source file:com.android.mms.quickmessage.QuickMessageWear.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; Intent i = getIntent();/* www . j a v a 2 s .c om*/ parseIntent(i); //Get partial Wakelock so that we can send the message even if phone is locked final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mWakeLock.acquire(); }
From source file:com.grarak.kerneladiutor.utils.Utils.java
public static boolean isScreenOn(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { return powerManager.isInteractive(); }/*from ww w . j a v a 2 s . c o m*/ return powerManager.isScreenOn(); }
From source file:us.dustinj.locationstore.io.LocationExporter.java
public LocationExporter(Context context, HttpStatusResponseHandler responseReceiver) { m_context = context;/*from ww w . ja v a2 s . c o m*/ m_responseReceiver = responseReceiver; m_appPrefs = AppSettings.GetSettings(context); PowerManager pm = (PowerManager) m_context.getSystemService(Context.POWER_SERVICE); m_wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); }
From source file:eu.faircode.netguard.DownloadTask.java
@Override protected void onPreExecute() { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); wakeLock.acquire();//from www .j av a 2s. c o m showNotification(0); Toast.makeText(context, context.getString(R.string.msg_downloading, url.toString()), Toast.LENGTH_SHORT) .show(); }
From source file:net.kayateia.lifestream.UploadService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(LOG_TAG, "UploadService kicked"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); // See CaptureService for comments on this wake lock arrangement. boolean needsRelease = true; try {//from w ww .j a v a 2 s. co m // If we don't release it within the timeout somehow, release it anyway. // This may interrupt a long backlog upload or something, but this // is really about as long as we can reasonably expect to take. Log.v(LOG_TAG, "Acquire wakelock"); if (wl != null) wl.acquire(WAKELOCK_TIMEOUT); if (!Network.IsActive(this)) { Log.i(LOG_TAG, "No network active, giving up"); return START_NOT_STICKY; } // Do the check in a thread. new AsyncTask<UploadService, Void, Void>() { @Override protected Void doInBackground(UploadService... svc) { svc[0].checkUploads(); return null; } @Override protected void onPostExecute(Void foo) { Log.v(LOG_TAG, "Release wakelock by worker"); if (wl != null && wl.isHeld()) wl.release(); } }.execute(this); needsRelease = false; } finally { if (needsRelease) { Log.v(LOG_TAG, "Release wakelock by default"); if (wl != null && wl.isHeld()) wl.release(); } } // There's no need to worry about this.. we'll get re-kicked by the alarm. return START_NOT_STICKY; }
From source file:com.rks.musicx.services.MediaButtonReceiver.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, "Musicx headset button"); mWakeLock.setReferenceCounted(false); }// w ww . j av a2 s . c o m // Make sure we don't indefinitely hold the wake lock under any circumstances mWakeLock.acquire(10000); mHandler.sendMessageDelayed(msg, delay); }
From source file:com.twofours.surespot.services.SurespotGcmListenerService.java
@Override public void onCreate() { super.onCreate(); mPm = (PowerManager) getSystemService(Context.POWER_SERVICE); mBuilder = new NotificationCompat.Builder(this); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); }
From source file:org.ntpsync.service.NtpSyncService.java
private static void getLocks(Context context) { // initialise the lock wakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NtpSyncWakeLock"); }
From source file:net.kayateia.lifestream.StreamService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(LOG_TAG, "Kicked"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); // See CaptureService for comments on this wake lock arrangement. boolean needsRelease = true; try {/*from w w w . j a va 2 s. c o m*/ // If we don't release it within the timeout somehow, release it anyway. // This may interrupt a long backlog download or something, but this // is really about as long as we can reasonably expect to take. Log.v(LOG_TAG, "Acquire wakelock"); if (wl != null) wl.acquire(WAKELOCK_TIMEOUT); if (!Network.IsActive(this)) { Log.i(LOG_TAG, "No network active, giving up"); return START_NOT_STICKY; } // Do the check in a thread. new AsyncTask<StreamService, Void, Void>() { @Override protected Void doInBackground(StreamService... svc) { svc[0].checkNewImages(); return null; } @Override protected void onPostExecute(Void foo) { Log.v(LOG_TAG, "Release wakelock by worker"); if (wl != null && wl.isHeld()) wl.release(); } }.execute(this); needsRelease = false; } finally { if (needsRelease) { Log.v(LOG_TAG, "Release wakelock by default"); if (wl != null && wl.isHeld()) wl.release(); } } // There's no need to worry about this.. we'll get re-kicked by the alarm. return START_NOT_STICKY; }