本文整理匯總了Java中android.os.PowerManager.WakeLock.isHeld方法的典型用法代碼示例。如果您正苦於以下問題:Java WakeLock.isHeld方法的具體用法?Java WakeLock.isHeld怎麽用?Java WakeLock.isHeld使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.os.PowerManager.WakeLock
的用法示例。
在下文中一共展示了WakeLock.isHeld方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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, "開啟屏幕常亮");
}
示例2: acquire
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
public static synchronized void acquire(Context context) {
WakeLock wakeLock = getLock(context);
if (!wakeLock.isHeld()) {
wakeLock.acquire();
//Log.d("alogcat", "wake lock acquired");
}
}
示例3: cancelKeepScreen
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
/**
* 取消屏幕常亮
*
* @param activity you know
*/
public static void cancelKeepScreen(Activity activity) {
WakeLock wakeLock = mWakeLockArray.get(activity);
if (wakeLock != null) {
if (wakeLock.isHeld()) {
wakeLock.release();
}
}
Log.i(TAG, "取消屏幕常亮");
}
示例4: _acquireWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
private boolean _acquireWakeLock(WakeLock lock, long timeout) {
synchronized (lock) {
if (!lock.isHeld()) {
if (timeout > 0) {
lock.acquire(timeout);
} else {
lock.acquire();
}
return true;
}
}
return false;
}
示例5: _releaseWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
private boolean _releaseWakeLock(WakeLock lock) {
synchronized (lock) {
if (lock.isHeld()) {
lock.release();
return true;
}
}
return false;
}
示例6: acquireWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
public static WakeLock acquireWakeLock(Context context,String tag)
{
//Setup a WakeLock
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag);
wakeLock.setReferenceCounted(true);
//acquire the lock
if(!wakeLock.isHeld())
{
wakeLock.acquire();
}
return wakeLock;
}
示例7: releaseWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
public static void releaseWakeLock(WakeLock wakeLock)
{
if(wakeLock != null)
{
if(wakeLock.isHeld())
{
wakeLock.release();
}
}
}
示例8: acquireWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
public static void acquireWakeLock(final String TAG, int levelAndFlags, Context context){
WakeLock wakeLock = wakeLocks.get(TAG);
if(wakeLock == null){
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(levelAndFlags, TAG);
wakeLocks.put(TAG, wakeLock);
wakeLock.acquire();
} else if(!wakeLock.isHeld()){
wakeLock.acquire();
} else {
Log.v(LOG_TAG, "Wakelock already acquired:" + TAG);
}
}
示例9: releaseWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
public static void releaseWakeLock(final String TAG){
WakeLock wakeLock = wakeLocks.get(TAG);
if(!Utility.checkForNullAndWarn(wakeLock, LOG_TAG)){
if(wakeLock.isHeld()) wakeLock.release();
//wakeLocks.remove(TAG); Not sure about this; might be good to keep the wakeLock object.
}
}
示例10: setWakeLock
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
private synchronized final void setWakeLock(boolean enableLock) {
WakeLock wl = wakeLock;
if (wl != null) {
if (wl.isHeld())
wl.release();
if (enableLock)
wl.acquire();
}
}
示例11: doInBackground
import android.os.PowerManager.WakeLock; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(String... strParams)
{
Boolean result = Boolean.FALSE;
// get a wakelock to hold for the duration of the background work. downloading
// may be slow. extraction usually isn't too slow but also takes a bit of time. limit the wakelock's time!
PowerManager powerManager = (PowerManager)m_ctx.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SettingsDownloaderWakeLock");
wakeLock.acquire(FOUR_MINUTES);
// download the file
String filename = downloadFile(strParams[0]);
if (filename != null)
{
File fSettingsZip = new File(filename);
if (fSettingsZip.exists() && !isCancelled())
{
try
{
m_logWriter.write("Successfully downloaded to: "+filename+"\n");
// extract to wanted directory
String destDir = strParams[1];
boolean bSuccess = extractSettingsZip(fSettingsZip, destDir);
result = (bSuccess ? Boolean.TRUE : Boolean.FALSE);
// delete settings zip
if (fSettingsZip.exists()) {
fSettingsZip.delete();
}
}
catch(Exception e)
{
Log.e("SettingsDownloader", "Error: "+e.toString());
}
}
}
// if our max time hasn't passed but work is done or an error occurred we bail out and release
if (wakeLock.isHeld())
{
wakeLock.release();
}
return result;
}