當前位置: 首頁>>代碼示例>>Java>>正文


Java WakeLock類代碼示例

本文整理匯總了Java中android.os.PowerManager.WakeLock的典型用法代碼示例。如果您正苦於以下問題:Java WakeLock類的具體用法?Java WakeLock怎麽用?Java WakeLock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WakeLock類屬於android.os.PowerManager包,在下文中一共展示了WakeLock類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wakeUpScreen

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
@SuppressWarnings("deprecation")
	private static void wakeUpScreen (Context ctx) {
		 PowerManager pm = (PowerManager)ctx.getSystemService(Context.POWER_SERVICE);
		 boolean isScreenOn = true;
		 // greater or equal to api level 20
		 if (Build.VERSION.SDK_INT > AlarmNotificationUtil.FAKE_KITKAT_WATCH) {
			 isScreenOn = pm.isInteractive();
		     Log.v("cpeng", "alarm screen is interactive");
		 }
		 else if (Build.VERSION.SDK_INT <= AlarmNotificationUtil.FAKE_KITKAT_WATCH) {
			 isScreenOn = pm.isScreenOn();
			 Log.v("cpeng", "alarm screen is on");
		 }
		 else {
			 Log.v("cpeng", "alarm screen OFF");
		 }

         if(isScreenOn==false)
         {
        	 WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,"ALock");
        	 wl.acquire(10000);
        	 wl.release();
//        	 WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"ACPULock");
//        	 wl_cpu.acquire(10000);
         }
	 }
 
開發者ID:michaelpengcn,項目名稱:notificationtest,代碼行數:27,代碼來源:AlarmNotificationReceiver.java

示例2: run

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
@Override
public void run() {
  notification              = initializeBackgroundNotification();
  PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
  WakeLock     wakeLock     = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration");

  try {
    wakeLock.acquire();

    setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null));

    SmsMigrator.migrateDatabase(ApplicationMigrationService.this,
                                masterSecret,
                                ApplicationMigrationService.this);

    setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null));

    setDatabaseImported(ApplicationMigrationService.this);
    stopForeground(true);
    notifyImportComplete();
    stopSelf();
  } finally {
    wakeLock.release();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:26,代碼來源:ApplicationMigrationService.java

示例3: startWakefulService

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
public static ComponentName startWakefulService(Context context, Intent intent) {
    ComponentName comp;
    synchronized (mActiveWakeLocks) {
        int id = mNextId;
        mNextId++;
        if (mNextId <= 0) {
            mNextId = 1;
        }
        intent.putExtra(EXTRA_WAKE_LOCK_ID, id);
        comp = context.startService(intent);
        if (comp == null) {
            comp = null;
        } else {
            WakeLock wl = ((PowerManager) context.getSystemService("power")).newWakeLock(1, "wake:" + comp.flattenToShortString());
            wl.setReferenceCounted(false);
            wl.acquire(60000);
            mActiveWakeLocks.put(id, wl);
        }
    }
    return comp;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:WakefulBroadcastReceiver.java

示例4: completeWakefulIntent

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
public static boolean completeWakefulIntent(Intent intent) {
    int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0);
    if (id == 0) {
        return false;
    }
    synchronized (mActiveWakeLocks) {
        WakeLock wl = (WakeLock) mActiveWakeLocks.get(id);
        if (wl != null) {
            wl.release();
            mActiveWakeLocks.remove(id);
            return true;
        }
        Log.w("WakefulBroadcastReceiver", "No active wake lock id #" + id);
        return true;
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:17,代碼來源:WakefulBroadcastReceiver.java

示例5: keepScreenOn

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
/**
 * 保持屏幕常亮
 *
 * @param activity you know
 */
public static void keepScreenOn(Activity activity) {
    WakeLock wakeLock = mWakeLockArray.get(activity);
    if (wakeLock == null) {
        PowerManager powerManager = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK,
                activity.getClass().getName());
    }

    if (!wakeLock.isHeld()) {
        wakeLock.acquire();
    }

    mWakeLockArray.put(activity, wakeLock);

    cancelLockScreen(activity);

    Log.i(TAG, "開啟屏幕常亮");
}
 
開發者ID:guiying712,項目名稱:AndroidModulePattern,代碼行數:24,代碼來源:ScreenLockUtil.java

示例6: onReceive

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
/**
 * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
 * TIME_SET, TIMEZONE_CHANGED
 */
@Override
public void onReceive(final Context context, Intent intent) {
  final String action = intent.getAction();
  Log.d("AlarmInitReceiver" + action);
  if (App.fejlsøgning) App.langToast("AlarmInitReceiver onReceive(" + intent);

  //final PendingResult result = goAsync();
  final WakeLock wl = AlarmAlertWakeLock.createPartialWakeLock(context);
  if (wl!=null) wl.acquire(); // fix for https://mint.splunk.com/dashboard/project/cd78aa05/errors/3315048120

  Alarms.setNextAlert(context);
  //      result.finish();
  Log.d("AlarmInitReceiver finished");
  if (wl!=null) wl.release(); // fix for https://mint.splunk.com/dashboard/project/cd78aa05/errors/3315048120
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:20,代碼來源:AlarmInitReceiver.java

示例7: getLock

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
synchronized private PowerManager.WakeLock getLock(Context context) {
    if (mWakeLock != null) {
        if (mWakeLock.isHeld())
            mWakeLock.release();
        mWakeLock = null;
    }

    if (mWakeLock == null) {
        PowerManager mgr = (PowerManager) context
                .getSystemService(Context.POWER_SERVICE);
        mWakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                StepService.class.getName());
        mWakeLock.setReferenceCounted(true);
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(System.currentTimeMillis());
        int hour = c.get(Calendar.HOUR_OF_DAY);
        if (hour >= 23 || hour <= 6) {
            mWakeLock.acquire(5000);
        } else {
            mWakeLock.acquire(300000);
        }
    }
    return (mWakeLock);
}
 
開發者ID:xfmax,項目名稱:BasePedo,代碼行數:25,代碼來源:StepService.java

示例8: getLock

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
synchronized private WakeLock getLock(Context context) {
    if (mWakeLock != null) {
        if (mWakeLock.isHeld())
            mWakeLock.release();
        mWakeLock = null;
    }

    if (mWakeLock == null) {
        PowerManager mgr = (PowerManager) context
                .getSystemService(Context.POWER_SERVICE);
        mWakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                StepService.class.getName());
        mWakeLock.setReferenceCounted(true);
        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(System.currentTimeMillis());
        int hour = c.get(Calendar.HOUR_OF_DAY);
        if (hour >= 23 || hour <= 6) {
            mWakeLock.acquire(5000);
        } else {
            mWakeLock.acquire(300000);
        }
    }

    return (mWakeLock);
}
 
開發者ID:aduroidpc,項目名稱:Running,代碼行數:26,代碼來源:StepService.java

示例9: registerWakeLockAcquirer

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
private void registerWakeLockAcquirer() {
    if (keepScreenOnMode == KeepScreenOnMode.Disabled) {
        Log.d("registerWakeLockAcquirer(): WakeLock not configured");
        return;
    }
    periodicalWakeLockAcquirer = new Timer();
    // run scheduled cell listener
    periodicalWakeLockAcquirer.schedule(new TimerTask() {
        private final String INNER_TAG = TAG + ".Periodical" + WakeLock.class.getSimpleName() + "Acquirer";

        @Override
        public void run() {
            synchronized (reacquireWakeLockLock) {
                WakeLock oldWakeLock = wakeLock;
                Log.d(INNER_TAG, "run(): New WakeLock acquire");
                wakeLock = createWakeLock(keepScreenOnMode);
                wakeLock.acquire(WAKE_LOCK_TIMEOUT);
                Log.d(INNER_TAG, "run(): Old WakeLock release");
                if (oldWakeLock != null && oldWakeLock.isHeld())
                    oldWakeLock.release();
            }
        }
    }, 0, WAKE_LOCK_ACQUIRE_INTERVAL);
}
 
開發者ID:zamojski,項目名稱:TowerCollector,代碼行數:25,代碼來源:CollectorService.java

示例10: onReceive

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
@Override
      @SuppressLint("Wakelock")
public void onReceive(Context context, Intent intent) {
	traceDebug(TAG, "Internal network status receive.");
	// we protect against the phone switching off
	// by requesting a wake lock - we request the minimum possible wake
	// lock - just enough to keep the CPU running until we've finished
	PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
	WakeLock wl = pm
			.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MQTT");
	wl.acquire();
	traceDebug(TAG,"Reconnect for Network recovery.");
	if (isOnline()) {
		traceDebug(TAG,"Online,reconnect.");
		// we have an internet connection - have another try at
		// connecting
		reconnect();
	} else {
		notifyClientsOffline();
	}

	wl.release();
}
 
開發者ID:Cirrus-Link,項目名稱:Sparkplug,代碼行數:24,代碼來源:MqttService.java

示例11: processLocation

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
private WeatherLocation processLocation(Location location) {
	if (location != null) {
		PowerManager powerManager = (PowerManager) mApplicationContext.getSystemService(Context.POWER_SERVICE);
		WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MobileWeatherProcessLocation");

		try {
			wakeLock.acquire();
			WeatherLocation loc = null;
			
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent()) {
				loc = reverseGeocode(location);
			}
			else {
				loc = new WeatherLocation();
				GPSLocation gpsLoc = new GPSLocation();
				gpsLoc.latitude = String.valueOf(location.getLatitude());
				gpsLoc.longitude = String.valueOf(location.getLongitude());
				loc.gpsLocation = gpsLoc;		
			}
			return loc;
		} finally {
			wakeLock.release();
		}
	}
	return null;
}
 
開發者ID:smartdevicelink,項目名稱:sdl_mobileweather_tutorial_android,代碼行數:27,代碼來源:WeatherLocationServices.java

示例12: loadPrerequisites

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
protected static void loadPrerequisites(Runnable paramRunnable)
{
  final PowerManager.WakeLock localWakeLock = ((PowerManager)FinskyApp.get().getSystemService("power")).newWakeLock(1, "ReschedulerStrategy");
  Runnable local1 = new Runnable()
  {
    private int mLoaded;
    
    public final void run()
    {
      this.mLoaded = (1 + this.mLoaded);
      if (this.mLoaded == 3)
      {
        this.val$onPrerequisitesLoaded.run();
        localWakeLock.release();
      }
    }
  };
  localWakeLock.acquire();
  FinskyApp.get().mLibraries.load(local1);
  FinskyApp.get().mAppStates.load(local1);
  GearheadStateMonitor.getInstance().initialize(local1);
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:23,代碼來源:ReschedulerStrategy.java

示例13: completeWakefulIntent

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
public static boolean completeWakefulIntent(Intent paramIntent)
{
  int i = paramIntent.getIntExtra("android.support.content.wakelockid", 0);
  if (i == 0) {
    return false;
  }
  synchronized (mActiveWakeLocks)
  {
    PowerManager.WakeLock localWakeLock = (PowerManager.WakeLock)mActiveWakeLocks.get(i);
    if (localWakeLock != null)
    {
      localWakeLock.release();
      mActiveWakeLocks.remove(i);
      return true;
    }
    Log.w("WakefulBroadcastReceiver", "No active wake lock id #" + i);
    return true;
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:20,代碼來源:WakefulBroadcastReceiver.java

示例14: startWakefulService

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
public static ComponentName startWakefulService(Context paramContext, Intent paramIntent)
{
  synchronized (mActiveWakeLocks)
  {
    int i = mNextId;
    int j = 1 + mNextId;
    mNextId = j;
    if (j <= 0) {
      mNextId = 1;
    }
    paramIntent.putExtra("android.support.content.wakelockid", i);
    ComponentName localComponentName = paramContext.startService(paramIntent);
    if (localComponentName == null) {
      return null;
    }
    PowerManager.WakeLock localWakeLock = ((PowerManager)paramContext.getSystemService("power")).newWakeLock(1, "wake:" + localComponentName.flattenToShortString());
    localWakeLock.setReferenceCounted(false);
    localWakeLock.acquire(60000L);
    mActiveWakeLocks.put(i, localWakeLock);
    return localComponentName;
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:23,代碼來源:WakefulBroadcastReceiver.java

示例15: a

import android.os.PowerManager.WakeLock; //導入依賴的package包/類
public static ComponentName a(Context paramContext, Intent paramIntent)
{
  synchronized (a)
  {
    int i = b;
    int j = 1 + b;
    b = j;
    if (j <= 0) {
      b = 1;
    }
    paramIntent.putExtra("android.support.content.wakelockid", i);
    ComponentName localComponentName = paramContext.startService(paramIntent);
    if (localComponentName == null) {
      return null;
    }
    PowerManager.WakeLock localWakeLock = ((PowerManager)paramContext.getSystemService("power")).newWakeLock(1, "wake:" + localComponentName.flattenToShortString());
    localWakeLock.setReferenceCounted(false);
    localWakeLock.acquire(60000L);
    a.put(i, localWakeLock);
    return localComponentName;
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:23,代碼來源:gk.java


注:本文中的android.os.PowerManager.WakeLock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。