[Android] 常用小功能

[Android] 常用小功能

Last update 2011/6/8

手機震動(Vibrator):

權限:android.permission.VIBRATE

Vibrator myVibrator = (Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
myVibrator.vibrate(500);

 

電源管理(Power Manager):

權限:

android.permission.WAKE_LOCK

android.permission.DEVICE_POWER

PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "map");
wakeLock.acquire(); //啟動
wakeLock.acquire(); //關閉

(截自官方)

Flag Value
CPU Screen Keyboard
PARTIAL_WAKE_LOCK On* Off Off
SCREEN_DIM_WAKE_LOCK On Dim Off
SCREEN_BRIGHT_WAKE_LOCK On Bright Off
FULL_WAKE_LOCK On Bright Bright
 

*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.

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.

 

有學到新的就補進來…

Dotblogs 的標籤: ,,