本文整理汇总了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;
}