本文整理匯總了Java中android.os.PowerManager類的典型用法代碼示例。如果您正苦於以下問題:Java PowerManager類的具體用法?Java PowerManager怎麽用?Java PowerManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PowerManager類屬於android.os包,在下文中一共展示了PowerManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.os.PowerManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity");
mWakeLock.acquire(2 * 60 * 1000L);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
window.setStatusBarColor(Color.TRANSPARENT);
}
setContentView(R.layout.activity_alarm);
if (getActivityComponent() != null) {
getActivityComponent().inject(this);
alarmPresenter.onAttach(this);
}
initViews();
bindEvents();
processIntent();
}
示例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: onRun
import android.os.PowerManager; //導入依賴的package包/類
@Override
public void onRun() throws IOException {
Log.w("DirectoryRefreshJob", "DirectoryRefreshJob.onRun()");
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Directory Refresh");
try {
wakeLock.acquire();
if (recipients == null) {
DirectoryHelper.refreshDirectory(context, KeyCachingService.getMasterSecret(context));
} else {
DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients, TextSecurePreferences.getLocalNumber(context));
}
SecurityEvent.broadcastSecurityUpdateEvent(context);
} finally {
if (wakeLock.isHeld()) wakeLock.release();
}
}
示例4: LinphoneManager
import android.os.PowerManager; //導入依賴的package包/類
protected LinphoneManager(final Context c) {
sExited = false;
echoTesterIsRunning = false;
mServiceContext = c;
basePath = c.getFilesDir().getAbsolutePath();
mLPConfigXsd = basePath + "/lpconfig.xsd";
mLinphoneFactoryConfigFile = basePath + "/linphonerc";
mLinphoneConfigFile = basePath + "/.linphonerc";
mLinphoneRootCaFile = basePath + "/rootca.pem";
mRingSoundFile = basePath + "/ringtone.mkv";
mRingbackSoundFile = basePath + "/ringback.wav";
mPauseSoundFile = basePath + "/hold.mkv";
mChatDatabaseFile = basePath + "/linphone-history.db";
mCallLogDatabaseFile = basePath + "/linphone-log-history.db";
mFriendsDatabaseFile = basePath + "/linphone-friends.db";
mErrorToneFile = basePath + "/error.wav";
mUserCertificatePath = basePath;
mPrefs = LinphonePreferences.instance();
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
mR = c.getResources();
mPendingChatFileMessage = new ArrayList<LinphoneChatMessage>();
}
示例5: run
import android.os.PowerManager; //導入依賴的package包/類
@Override
public void run() {
super.run();
PowerManager.WakeLock lock = getLock(mContext);
while (isRunning) {
AnimeDownloadTask task = mTaskQueue.poll();
if (task != null) {
if (!lock.isHeld()) {
lock.acquire();
}
mDownloadingTasks.add(task);
task.execute();
}
}
if (lock.isHeld()) {
lock.release();
}
}
示例6: LockManager
import android.os.PowerManager; //導入依賴的package包/類
public LockManager(Context context) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
proximityLock = new ProximityLock(pm);
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");
fullLock.setReferenceCounted(false);
partialLock.setReferenceCounted(false);
wifiLock.setReferenceCounted(false);
accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
@Override
public void orientationChanged(int newOrientation) {
orientation = newOrientation;
Log.d(TAG, "Orentation Update: " + newOrientation);
updateInCallLockState();
}
});
wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
示例7: wakeAndUnlock
import android.os.PowerManager; //導入依賴的package包/類
private void wakeAndUnlock()
{
//獲取電源管理器對象
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//點亮屏幕
wl.acquire(1000);
//得到鍵盤鎖管理器對象
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解鎖
kl.disableKeyguard();
}
示例8: acquireWakeLocks
import android.os.PowerManager; //導入依賴的package包/類
/**
*
*/
private void acquireWakeLocks() {
if(_wakeLock == null) {
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BlockchainServiceLockTag");
}
if (_wifiLock == null) {
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
_wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "BlockchainServiceWifiLockTag");
}
if (!_wakeLock.isHeld())
_wakeLock.acquire();
if (!_wifiLock.isHeld())
_wifiLock.acquire();
}
示例9: toggleWakeUpWithProximityFeature
import android.os.PowerManager; //導入依賴的package包/類
private static void toggleWakeUpWithProximityFeature(boolean enabled) {
try {
if (enabled) {
mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
} else {
unregisterProxSensorListener();
mProxSensor = null;
mSensorManager = null;
mWakeLock = null;
}
if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled);
} catch (Throwable t) {
XposedBridge.log(t);
}
}
示例10: run
import android.os.PowerManager; //導入依賴的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();
}
}
示例11: 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;
}
示例12: wakeAndUnlock
import android.os.PowerManager; //導入依賴的package包/類
private void wakeAndUnlock() {
//獲取電源管理器對象
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
//獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//點亮屏幕
wl.acquire(1000);
//得到鍵盤鎖管理器對象
KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("unLock");
//解鎖
kl.disableKeyguard();
}
示例13: wakeAndUnlock
import android.os.PowerManager; //導入依賴的package包/類
public static void wakeAndUnlock() {
//獲取電源管理器對象
PowerManager pm = getPowerManager();
//獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");
//點亮屏幕
wl.acquire(1000);
//得到鍵盤鎖管理器對象
KeyguardManager km = getKeyguardManager();
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");
//解鎖
kl.disableKeyguard();
}
示例14: 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();
}
}
示例15: keepAwake
import android.os.PowerManager; //導入依賴的package包/類
/**
* Put the service in a foreground state to prevent app from being killed
* by the OS.
*/
private void keepAwake() {
JSONObject settings = BackgroundMode.getSettings();
boolean isSilent = settings.optBoolean("silent", false);
if (!isSilent) {
startForeground(NOTIFICATION_ID, makeNotification());
}
PowerManager powerMgr = (PowerManager)
getSystemService(POWER_SERVICE);
wakeLock = powerMgr.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");
wakeLock.acquire();
}