Best code examples for Android PowerManager class (android.os.PowerManager)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android PowerManager class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android PowerManager examples from Open Source projects
This code example shows how to use the following methods: newWakeLock, getClass
	private final static int WAIT_FOR_PROXIMITY_NEGATIVE = 1;
	private final static int WAKE_UP_IMMEDIATELY = 0;
 
	public WakeLockManager(Context context){
		mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
		mFullLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK
											  | PowerManager.ACQUIRE_CAUSES_WAKEUP
											  | PowerManager.ON_AFTER_RELEASE, LOG_TAG);
		mPartialLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOG_TAG);
 
		// Check if PROXIMITY_SCREEN_OFF_WAKE_LOCK is implemented, not part of public api. 
		try { 
			Method method = mPowerManager.getClass().getDeclaredMethod("getSupportedWakeLockFlags");
			int supportedWakeLockFlags = (Integer) method.invoke(mPowerManager);
			Field field = PowerManager.class.getDeclaredField("PROXIMITY_SCREEN_OFF_WAKE_LOCK");
			int proximityScreenOffWakeLock = (Integer) field.get(null);
			if ((supportedWakeLockFlags & proximityScreenOffWakeLock) != 0x0) {
				mProximityLock = mPowerManager.newWakeLock(proximityScreenOffWakeLock, LOG_TAG);
			} 
		} catch (Exception e){

7
CodeRank
This code example shows how to use the following methods: newWakeLock
   
  synchronized private static PowerManager.WakeLock getLock(Context context) {
    if (lockStatic==null) {
      PowerManager mgr=(PowerManager)context.getSystemService(Context.POWER_SERVICE);
       
      lockStatic=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                            LOCK_NAME_STATIC);
      lockStatic.setReferenceCounted(true);
    } 
     
    return(lockStatic);
  } 
   
  public WakefulIntentService(String name) {
    super(name);
  } 
   
  @Override 
  final protected void onHandleIntent(Intent intent) {
    try { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: newWakeLock
    static void runIntentInService(Context context, Intent intent) {
        if (mWakeLock == null) {
            // This is called from BroadcastReceiver, there is no init. 
            PowerManager pm = 
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
                    WAKELOCK_KEY);
        } 
        mWakeLock.acquire();
        
        // Use a naming convention, similar with how permissions and intents are  
        // used. Alternatives are introspection or an ugly use of statics.  
        String receiver = context.getPackageName() + ".C2DMReceiver";
        intent.setClassName(context, receiver);
         
        context.startService(intent);
 
    } 
     
     
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: newWakeLock
 
  public MmscProcessor(Context context) {
    this.context = context;
    PowerManager powerManager         = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
    this.connectivityManager          = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
    this.wakeLock                     = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MMS Connection");
    this.wakeLock.setReferenceCounted(false);
  } 
 
  protected String getApnInformation() {
    return connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS).getExtraInfo();
  } 
 
  protected boolean isConnected() { 
    NetworkInfo info = connectivityManager.getNetworkInfo(TYPE_MOBILE_MMS);
 
    Log.w("MmsService", "NetworkInfo: " + info);
 
    if ((info == null) || (info.getType() != TYPE_MOBILE_MMS) || !info.isConnected())
      return false; 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: newWakeLock
Related Android PowerManager Questions & Answers:
Other Android PowerManager Examples
9:	        if (wakeLock != null) wakeLock.release();
10:	
11:	        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
12:	        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
13:	                PowerManager.ACQUIRE_CAUSES_WAKEUP |
-
9:	        if (wakeLock != null) wakeLock.release();
10:	
11:	        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
12:	        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
13:	                PowerManager.ACQUIRE_CAUSES_WAKEUP |

Read More

See Code Examples for Android PowerManager Methods: