本文整理汇总了Java中android.os.PowerManager.WakeLock方法的典型用法代码示例。如果您正苦于以下问题:Java PowerManager.WakeLock方法的具体用法?Java PowerManager.WakeLock怎么用?Java PowerManager.WakeLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.PowerManager
的用法示例。
在下文中一共展示了PowerManager.WakeLock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProximityLock
import android.os.PowerManager; //导入方法依赖的package包/类
private Optional<PowerManager.WakeLock> getProximityLock(PowerManager pm) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
"Signal Proximity Lock"));
} else {
return Optional.absent();
}
} else {
try {
return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall"));
} catch (Throwable t) {
Log.e(TAG, "Failed to create proximity lock", t);
return Optional.absent();
}
}
}
示例2: onReceive
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context c, Intent i) {
final long alarmid = i.getLongExtra(ALARM_ID, -1);
@SuppressWarnings("deprecation") // SCREEN_DIM_WAKE_LOCK
PowerManager.WakeLock w =
((PowerManager)c.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP, "wake id " + nextid);
w.setReferenceCounted(false);
w.acquire();
locks.put(nextid, w);
Log.i(TAG, "Acquired lock " + nextid + " for alarm " + alarmid);
c.startService(new Intent(c, AlarmNotificationService.class)
.putExtra(ALARM_ID, alarmid)
.putExtra(COMMAND, TRIGGER_ALARM_NOTIFICATION)
.putExtra(WAKELOCK_ID, nextid++));
}
示例3: wakeScreen
import android.os.PowerManager; //导入方法依赖的package包/类
/**
* Waking up the screen
* * * */
private static void wakeScreen(Context context){
// Waking the screen so the user will see the notification
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH)
isScreenOn = pm.isScreenOn();
else
isScreenOn = pm.isInteractive();
if(!isScreenOn)
{
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
|PowerManager.ON_AFTER_RELEASE
|PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyLock");
wl.acquire(5000);
wl.release();
}
}
示例4: onStartCommand
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
PowerManager.WakeLock lock = getLock(this.getApplicationContext());
if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
lock.acquire();
}
if (mServiceHandler != null) {
if (intent != null && intent.getExtras() != null) {
// For each start request, send a message to start a job and deliver the
// start ID so we know which request we're stopping when we finish the job
Message msg = mServiceHandler.obtainMessage();
msg.arg1 = startId;
msg.setData(intent.getExtras());
mServiceHandler.sendMessage(msg);
} else
stopSelf();
}
// If we get killed, after returning from here, restart
return START_STICKY;
}
示例5: handleMessage
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
try {
Bundle extras = msg.getData();
if (extras != null) {
final String animeURL = extras.getString(Constants.ANIME_URL);
int mType = Parser.getTypeByURL(animeURL);
WriteLog.appendLog(mTag, "parsing " + animeURL);
if (mType == -1)
return;
showNotification(animeURL);
mParser = Parser.getExistingInstance(mType);
if (Parser.isDeadSource(mParser)) {
if (MAVApplication.getInstance().getRepository().isFavorite(animeURL)) {
FavoriteRecord lRecord = MAVApplication.getInstance().getRepository().getFavoriteByAnimeUrl(animeURL);
MAVApplication.getInstance().getRepository().deleteFavorite(animeURL);
}
return;
}
if (mParser.isCloudFlareDDOSEnabled) {
webview = new WebView(mService.get());
WebSettings websettings = webview.getSettings();
websettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new ParserWebClient(animeURL));
webview.loadUrl(mParser.getServerUrl());
} else {
parseData(animeURL);
}
}
} finally {
PowerManager.WakeLock lock = getLock(mContext);
if (lock.isHeld()) {
lock.release();
}
}
}
示例6: onCreate
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add flag to current window
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
// init KeyguardManager
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
if (keyguardManager.inKeyguardRestrictedInputMode()) {
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(getLocalClassName());
keyguardLock.disableKeyguard();
}
// wake up screen light
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "");
wakeLock.acquire();
// finish current activity
finish();
}
示例7: openWakeLock
import android.os.PowerManager; //导入方法依赖的package包/类
/**
* 打开休眠锁只能保持手机不休眠
* @param context
*/
@Deprecated
public static void openWakeLock(Context context) {
PowerManager powerManager = (PowerManager) context.getSystemService(Service.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Lock");
//是否需计算锁的数量
wakeLock.setReferenceCounted(false);
//请求常亮,onResume()
wakeLock.acquire();
}
示例8: wakeUpAndUnlock
import android.os.PowerManager; //导入方法依赖的package包/类
private void wakeUpAndUnlock(Context context)
{
KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
// 解锁
kl.disableKeyguard();
// 获取电源管理器对象
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
// 获取PowerManager.WakeLock对象,后面的参数|表示同时传入两个值,最后的是LogCat里用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "bright");
// 点亮屏幕
wl.acquire();
// 释放
wl.release();
}
示例9: createPartialWakeLock
import android.os.PowerManager; //导入方法依赖的package包/类
public static PowerManager.WakeLock createPartialWakeLock(Context context) {
PowerManager pm =
(PowerManager) context.getSystemService(Context.POWER_SERVICE);
//return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Log.LOGTAG);
//if (App.PRODUKTION) App.kortToast("createPartialWakeLock");
return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE
| PowerManager.ACQUIRE_CAUSES_WAKEUP, AlarmAlertWakeLock.class.getName());
}
示例10: onReceive
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
wl.acquire();
checkPlanned(context);
wl.release();
}
示例11: systemUnLock
import android.os.PowerManager; //导入方法依赖的package包/类
public static void systemUnLock() {
PowerManager pm = (PowerManager) ClockApplication.getContext().getSystemService(Activity.POWER_SERVICE);
PowerManager.WakeLock mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "SimpleTimer");
mWakelock.acquire();
}
示例12: setWakeLock
import android.os.PowerManager; //导入方法依赖的package包/类
public void setWakeLock(PowerManager.WakeLock wakeLock) {
this.wakeLock = wakeLock;
}
示例13: getWakeLock
import android.os.PowerManager; //导入方法依赖的package包/类
public PowerManager.WakeLock getWakeLock() {
return wakeLock;
}
示例14: run
import android.os.PowerManager; //导入方法依赖的package包/类
/**
* Executes the download in a separate thread
*/
public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
State state = new State(mInfo, mService);
PowerManager.WakeLock wakeLock = null;
int finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;
try {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG);
wakeLock.acquire();
if (Constants.LOGV) {
Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
Log.v(Constants.TAG, " at " + mInfo.mUri);
}
boolean finished = false;
while (!finished) {
if (Constants.LOGV) {
Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
Log.v(Constants.TAG, " at " + mInfo.mUri);
}
// Set or unset proxy, which may have changed since last GET
// request.
// setDefaultProxy() supports null as proxy parameter.
URL url = new URL(state.mRequestUri);
HttpURLConnection request = (HttpURLConnection)url.openConnection();
request.setRequestProperty("User-Agent", userAgent());
try {
executeDownload(state, request);
finished = true;
} catch (RetryDownload exc) {
// fall through
} finally {
request.disconnect();
request = null;
}
}
if (Constants.LOGV) {
Log.v(Constants.TAG, "download completed for " + mInfo.mFileName);
Log.v(Constants.TAG, " at " + mInfo.mUri);
}
finalizeDestinationFile(state);
finalStatus = DownloaderService.STATUS_SUCCESS;
} catch (StopRequest error) {
// remove the cause before printing, in case it contains PII
Log.w(Constants.TAG,
"Aborting request for download " + mInfo.mFileName + ": " + error.getMessage());
error.printStackTrace();
finalStatus = error.mFinalStatus;
// fall through to finally block
} catch (Throwable ex) { // sometimes the socket code throws unchecked
// exceptions
Log.w(Constants.TAG, "Exception for " + mInfo.mFileName + ": " + ex);
finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;
// falls through to the code that reports an error
} finally {
if (wakeLock != null) {
wakeLock.release();
wakeLock = null;
}
cleanupDestination(state, finalStatus);
notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter,
state.mRedirectCount, state.mGotData, state.mFilename);
}
}
示例15: doInBackground
import android.os.PowerManager; //导入方法依赖的package包/类
@Override
protected Throwable doInBackground(String... params) {
// Get wakelock
PowerManager pm = (PowerManager) ActivityShare.this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XPrivacy.Toggle");
wl.acquire();
try {
// Get data
mProgressCurrent = 0;
List<Integer> lstUid = mAppAdapter.getListUid();
final String restrictionName = params[0];
int actionId = ((RadioGroup) ActivityShare.this.findViewById(R.id.rgToggle)).getCheckedRadioButtonId();
Spinner spTemplate = ((Spinner) ActivityShare.this.findViewById(R.id.spTemplate));
String templateName = Meta.cTypeTemplate;
if (spTemplate.getSelectedItemPosition() > 0)
templateName = Meta.cTypeTemplate + spTemplate.getSelectedItemPosition();
for (Integer uid : lstUid)
try {
if (mAbort)
throw new AbortException(ActivityShare.this);
// Update progess
publishProgress(++mProgressCurrent, lstUid.size() + 1);
setState(uid, STATE_RUNNING, null);
List<Boolean> oldState = PrivacyManager.getRestartStates(uid, restrictionName);
if (actionId == R.id.rbClear) {
PrivacyManager.deleteRestrictions(uid, restrictionName, (restrictionName == null));
if (restrictionName == null) {
PrivacyManager.deleteUsage(uid);
PrivacyManager.deleteSettings(uid);
}
}
else if (actionId == R.id.rbRestrict) {
PrivacyManager.setRestriction(uid, restrictionName, null, true, false);
PrivacyManager.updateState(uid);
}
else if (actionId == R.id.rbTemplateCategory)
PrivacyManager.applyTemplate(uid, templateName, restrictionName, false, true, false);
else if (actionId == R.id.rbTemplateFull)
PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, true, false);
else if (actionId == R.id.rbTemplateMergeSet)
PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, false, false);
else if (actionId == R.id.rbTemplateMergeReset)
PrivacyManager.applyTemplate(uid, templateName, restrictionName, true, false, true);
else if (actionId == R.id.rbEnableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(true));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(false));
} else if (actionId == R.id.rbDisableOndemand) {
PrivacyManager.setSetting(uid, PrivacyManager.cSettingOnDemand, Boolean.toString(false));
PrivacyManager.setSetting(uid, PrivacyManager.cSettingNotify, Boolean.toString(true));
} else
Util.log(null, Log.ERROR, "Unknown action=" + actionId);
List<Boolean> newState = PrivacyManager.getRestartStates(uid, restrictionName);
setState(uid, STATE_SUCCESS, !newState.equals(oldState) ? getString(R.string.msg_restart)
: null);
} catch (Throwable ex) {
setState(uid, STATE_FAILURE, ex.getMessage());
return ex;
}
} finally {
wl.release();
}
return null;
}