`
丁志宏
  • 浏览: 14624 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

翻译 android.os.PowerManager

阅读更多

<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } H1 { margin-bottom: 0.08in } H1.western { font-family: "Times New Roman", serif } H1.cjk { font-family: "DejaVu Sans" } H1.ctl { font-family: "Lohit Hindi" } TD P { margin-bottom: 0in } H2 { margin-bottom: 0.08in } H2.ctl { font-family: "Lohit Hindi" } PRE.cjk { font-family: "DejaVu Sans", monospace } TH P { margin-bottom: 0in } CODE.cjk { font-family: "DejaVu Sans", monospace } -->

public class

PowerManager

extends Object

java.lang.Object

   ↳

android.os.PowerManager

类概括

Class Overview

 

本类使你能控制设备能量状态。

This class gives you control of the power state of the device.

 

设备电池生命将会受到这个API的使用的重大影响。除非你真正需要他们不要获得WakeLocks,尽可能使用最小等级,并且确保一旦你能够就释放他。

Device battery life will be significantly affected by the use of this API. Do not acquire WakeLocks unless you really need them, use the minimum levels possible, and be sure to release it as soon as you can.

 

你可以通过调用Context.getSystemService()获得这个类的一个实例。

You can obtain an instance of this class by calling Context.getSystemService().

 

首先你要用到的APInewWakeLock()。这个方法将建立一个PowerManager.WakeLock对象。你能够这样使用方法通过这个对象来控制设备的能量状态。实践起来十分简单:

The primary API you'll use is newWakeLock(). This will create a PowerManager.WakeLock object. You can then use methods on this object to control the power state of the device. In practice it's quite simple:

 

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
 wl.acquire();
   ..screen will stay on during this section..
 wl.release();
 

 

以下定义的标志,以及对系统能量的不同影响。有些标志是相互独立-你可能仅指定他们之一。

The following flags are defined, with varying effects on system power. These flags are mutually exclusive - you may only specify one of them.

Flag Value

CPU

Screen

Keyboard

PARTIAL_WAKE_LOCK

SCREEN_DIM_WAKE_LOCK

SCREEN_BRIGHT_WAKE_LOCK

FULL_WAKE_LOCK

On*

Off

Off

On

Dim

Off

On

Bright

Off

On

Bright

Bright

 

*如果你获得一个不完整的wakelock,则CPU会继续运行,不必顾及任何计时器甚至用户按下power键后。对于所有的其他的wakelockCPU在运行,但用户可以直接用power键使设备休眠。

*If you hold a partial wakelock, the CPU will continue to run, irrespective of any timers and even after the user presses the power button. In all other wakelocks, the CPU will run, but the user can still put the device to sleep using the power button.

 

另外,你能加两个以上的标志,这些仅能影响屏幕的行为。这些标志当组合中有一个PARTIAL_WAKE_LOCK时将没有效果。

In addition, you can add two more flags, which affect behavior of the screen only. These flags have no effect when combined with a PARTIAL_WAKE_LOCK.

Flag Value

Description

ACQUIRE_CAUSES_WAKEUP

ON_AFTER_RELEASE

 

正常的wake lock不会实际转到照明。反而,他们使照明保持自他打开时(例如,来自用户activity)。这个标志会强制屏幕和/或键盘立即打开,当这个wakelock已获取时。一个典型用法是将哪些重要的通知立即让用户看到。

Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.

 

如果这个标志被设置,用户activity计时器当WakeLock被释放时会重新设定,因为照明保持一点长。这个可以用于降低闪烁如果你是在wake lock状态下循环。

If this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions.

Summary

Nested Classes

class

PowerManager.WakeLock

类让你说你需要有这个设备。

Class lets you say that you need to have the device on. 

Constants

int

ACQUIRE_CAUSES_WAKEUP

正常的wake lock不会实际的唤醒设备,他们自他准备好则保持着。

Normally wake locks don't actually wake the device, they just cause it to remain on once it's already on.

int

FULL_WAKE_LOCK

Wake lock 以确保屏幕和键盘全部点亮。

Wake lock that ensures that the screen and keyboard are on at full brightness.

int

ON_AFTER_RELEASE

当这个wake lock已释放时,拨开了用户界面的计时器所以屏幕停留稍微长。

When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

int

PARTIAL_WAKE_LOCK

Wake lock以确保CPU运行。

Wake lock that ensures that the CPU is running.

int

SCREEN_BRIGHT_WAKE_LOCK

Wake lock以确保屏幕全亮;键盘背光允许关闭。

Wake lock that ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off.

int

SCREEN_DIM_WAKE_LOCK

Wake lock以确保屏幕打开(但可以是暗淡的);键盘背光将允许关闭。

Wake lock that ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off.

Public Methods

void

goToSleep(long time)

强制设备进入休眠。

Force the device to go to sleep.

boolean

IsScreenOn()

返回屏幕是否当前亮着。

Returns whether the screen is currently on.

PowerManager.WakeLock

newWakeLock(int flags, String tag)

得到一个Wake lock在这个标志参数的级别。

Get a wake lock at the level of the flags parameter.

void

reboot(String reason)

重启设备

Reboot the device.

void

userActivity(long when, boolean noChangeLights)

用户界面发生。

User activity happened.

 

分享到:
评论

相关推荐

    Unity调用Android系统PowerManager类功能.zip

    在Android中,你需要创建一个BroadcastReceiver监听ACTION_SHUTDOWN广播,然后在接收到广播时调用`powerManager.shutdown(false)`,第二个参数表示是否等待所有正在运行的任务完成。 - `reboot(String reason)`方法...

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    PowerManager and WakeLocks JobScheduler Accessing Location-Based Services The Fused Location Provider Working with the Clipboard Telephony Working With SMS NFC Device Administration Basic Use of ...

    android开发之“小镜子”app源码

    private PowerManager.WakeLock mWakeLock; private Bitmap bmp; private SurfaceView mSurfaceView; private LinearLayout llBottom, llCamera, llSave, llShare; private SurfaceHolder holder; private ...

    Android powermanger wakelock

    Android 提供了现成 android.os.PowerManager 类 , 类中 提供newWakeLock(int flags, String tag)方法 来取得 应用层的锁, 此函数的定义 frameworks/base/core/java/android/os/PowerManager.java 应用程序 在...

    Unity调用Android JAR

    AndroidJavaObject wakeLock = powerManager.Call("newWakeLock", wakeLockClass.GetStatic("PARTIAL_WAKE_LOCK"), "MyAppWakeLock"); wakeLock.Call("acquire"); } private void ReleaseWakeLock() { if ...

    android 休眠和唤醒

    调用`goToSleep`时,你需要传入一个参数,即休眠原因的标识码,这有助于系统追踪休眠的原因,例如`PowerManager.SLEEP_REASON_USER`表示用户手动触发的休眠。 `wakeUp`方法则是用于唤醒设备的。当设备处于休眠状态...

    android点击图标关闭屏幕

    powerManager.goToSleep(0); // 结束当前Activity,防止再次显示 finish(); } } ``` 3. 权限申请:在Android 6.0及以上版本,调用`goToSleep()`方法需要申请` android.permission.DEVICE_POWER`权限。在...

    Android Power Management.pdf

    - `frameworks/base/core/java/android/os/PowerManager.java` - `frameworks/base/services/java/com/android/server/PowerManagerService.java` - `frameworks/base/core/java/android/os/Power.java` - `...

    Android一键锁屏功能源码.zip

    mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "ScreenLocker"); } public void lockScreen() { if (mWakeLock != null && !mWakeLock.isHeld...

    Android中文API合集

    最后,Android还提供了丰富的系统服务,如地理位置服务(`LocationManager`)、通知管理(`NotificationManager`)、电源管理(`PowerManager`)等,开发者可以通过`Context`对象获取这些服务并进行相应的操作。...

    Android Power Manager

    Android 提供了现成的 android.os.PowerManager 类,用于控制设备的电源状态的切换,该类对外有三个接口函数:goToSleep、newWakeLock 和 userActivity。 在应用层面,开发者可以使用 PowerManager 类来控制设备的...

    Android系统关机的全流程解析

    在PowerManager的API文档中,给出了一个关机/重启接口: public void reboot (String reason) 对于这个接口的描述很简单,...1.frameworks/base/core/java/android/os/PowerManager.java /** * Reboot the device. W

    Android实例之屏幕操持常亮

    在`Android.JNI.PowerManager.pas`文件中,包含了与Java `PowerManager`类相关的Delphi实现。 6. **使用FMX(FireMonkey)框架**: 从`Unit1.NmXhdpiPh.fmx`和`Unit1.fmx`文件名推测,这个实例是基于FireMonkey...

    Android电源管理.doc

    - onCreate()中创建并获取唤醒锁:`mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "XYTEST"); mWakeLock.acquire();` - onDestroy()中释放唤醒锁:`mWakeLock.release();` 2. ...

    Android保持屏幕常亮

    Android保持屏幕常亮,PowerManager.WakeLock的使用 package com.hebaijun.wakelock; import android.app.Activity; import android.os.Bundle; import android.os.PowerManager; public class WakeLockActivity ...

    android电源管理

    - frameworks/base/core/java/android/os/PowerManager.java - frameworks/base/services/java/com/android/server/PowerManagerService.java - frameworks/base/core/java/android/os/Power.java - frameworks/...

    android实现关机和重启.zip

    例如,可能有一个名为`android.os.PowerManager`的类,它包含未公开的`shutdown()`或`reboot()`方法。这需要深入理解和熟悉Android系统源码。 5. **第三方库**: 有一些第三方库,如`android-shutdown-reboot`,...

    小米便签部分代码精读注释

    import android.os.PowerManager; import android.provider.Settings; import android.view.Window; import android.view.WindowManager; import net.micode.notes.R; import net.micode.notes.data.Notes; import ...

    android 重启手机

    import android.os.PowerManager; public class RebootHelper { public static void reboot(Context context) { if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN_MR2) { PowerManager pm = ...

    Android Power Management

    - `PowerManager.java` - `PowerManagerService.java` - `Power.java` - `android_os_power.cpp` `PowerManagerService.java`是关键服务,负责处理电源管理的逻辑;`Power.java`提供底层函数接口,与JNI层交互;JNI...

Global site tag (gtag.js) - Google Analytics