待机后定时开启 (亮屏,自动解锁)程序实现?可以不? RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏 //设置屏幕不休眠 getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 你参考下这个例子:http://www.eoeandroid.com/thread-58403-1-1.html 这段代码可以实现亮屏,定时可以通过继承android.os.CountDownTimer实现import android.content.Context;import android.content.SharedPreferences;import android.os.PowerManager;import android.preference.PreferenceManager;public class ManageWakeLock { private static PowerManager.WakeLock myWakeLock; // private static int TIMEOUT_SECS = 10; public static void acquire(Context context) { if (myWakeLock != null) { // myWakeLock.release(); return; } PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean wakeScreen = true; // int flags = PowerManager.ON_AFTER_RELEASE; int flags = 0; if (wakeScreen) { ManageKeyguard.disableKeyguard(context); flags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP; } else { flags = PowerManager.PARTIAL_WAKE_LOCK; } myWakeLock = pm.newWakeLock(flags, Log.LOGTAG); if (Log.DEBUG) Log.v("Wakelock acquired"); // myWakeLock.acquire(TIMEOUT_SECS * 1000); myWakeLock.acquire(); } static void release() { if (myWakeLock != null) { if (Log.DEBUG) Log.v("Wakelock released"); myWakeLock.release(); myWakeLock = null; } }} 定时的话网上例子比较多。主要是用AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);然后定义自己的PendingIntent:Intent intent = new Intent(AlarmTest.this, MyAlarmBroadCast.class);PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);接着调用set方法来设置到时间后触发intent里的广播接收:alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);然后就是唤醒屏幕和解锁键盘了,WalkLock - 顾名思义 唤醒锁 点亮屏幕用的,KeyguardLock - 顾名思义 键盘锁 解锁键盘用的,唤醒屏幕和解锁屏幕的代码如下: public void unlockScreen() { // 获取PowerManager的实例 PowerManager pm = (PowerManager) mContext .getSystemService(Context.POWER_SERVICE); // 得到一个WakeLock唤醒锁 mWakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "SimpleTimer"); if (!mWakelock.isHeld()) { // 唤醒屏幕 mWakelock.acquire(); } // 获得一个KeyguardManager的实例 km = (KeyguardManager) mContext .getSystemService(Context.KEYGUARD_SERVICE); // 得到一个键盘锁KeyguardLock mKeyguardLock = km.newKeyguardLock("SimpleTimer"); if (km.inKeyguardRestrictedInputMode()) { // 解锁键盘 mKeyguardLock.disableKeyguard(); } }注意,这里使用的mWakelock.isHeld())来判断屏幕当前是否是休眠状态,从Android 2.1 API Level7开始增加了一个判断屏幕是否处于点亮状态可以使用public boolean isScreenOn ()这个方法。锁屏幕的代码是public void lockScreen() { // release screen if (!km.inKeyguardRestrictedInputMode()) { // 锁键盘 mKeyguardLock.reenableKeyguard(); } // 使屏幕休眠 if (mWakelock.isHeld()) { mWakelock.release(); } }这里要注意,如果没有锁键盘而直接调用mWakelock.release()会产生一个异常。所以一定要先把键盘锁了然后再使屏幕休眠。来自:http://www.devdiv.com/thread-64416-1-1.html Android GPS位置获取 为什么总是不能运行??!!! Android 播放MP3 报错 android kernel 黑屏 图片进度条 TabHost里加ListView怎么加啊? #求助安卓创建工程时报错# 点击ListView中的item时没有反映 Android 适配1080P手机屏幕,如何新建dimens文件夹? 视频通话中,两个surfaceview如何互换各自显示内容? 用Eclipse开发Android 调试问题,请教各位前辈! re-parented什么意思 限制Android ScrollView的区域
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏
//设置屏幕不休眠
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
import android.content.Context;
import android.content.SharedPreferences;
import android.os.PowerManager;
import android.preference.PreferenceManager;public class ManageWakeLock {
private static PowerManager.WakeLock myWakeLock; // private static int TIMEOUT_SECS = 10; public static void acquire(Context context) {
if (myWakeLock != null) {
// myWakeLock.release();
return;
} PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean wakeScreen = true; // int flags = PowerManager.ON_AFTER_RELEASE;
int flags = 0;
if (wakeScreen) {
ManageKeyguard.disableKeyguard(context);
flags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP;
} else {
flags = PowerManager.PARTIAL_WAKE_LOCK;
} myWakeLock = pm.newWakeLock(flags, Log.LOGTAG);
if (Log.DEBUG) Log.v("Wakelock acquired");
// myWakeLock.acquire(TIMEOUT_SECS * 1000);
myWakeLock.acquire();
} static void release() {
if (myWakeLock != null) {
if (Log.DEBUG) Log.v("Wakelock released");
myWakeLock.release();
myWakeLock = null;
}
}
}
然后定义自己的PendingIntent:
Intent intent = new Intent(AlarmTest.this, MyAlarmBroadCast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
接着调用set方法来设置到时间后触发intent里的广播接收:
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);然后就是唤醒屏幕和解锁键盘了,WalkLock - 顾名思义 唤醒锁 点亮屏幕用的,KeyguardLock - 顾名思义 键盘锁 解锁键盘用的,唤醒屏幕和解锁屏幕的代码如下:
public void unlockScreen() {
// 获取PowerManager的实例
PowerManager pm = (PowerManager) mContext
.getSystemService(Context.POWER_SERVICE);
// 得到一个WakeLock唤醒锁
mWakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, "SimpleTimer");
if (!mWakelock.isHeld()) {
// 唤醒屏幕
mWakelock.acquire();
} // 获得一个KeyguardManager的实例
km = (KeyguardManager) mContext
.getSystemService(Context.KEYGUARD_SERVICE);
// 得到一个键盘锁KeyguardLock
mKeyguardLock = km.newKeyguardLock("SimpleTimer");
if (km.inKeyguardRestrictedInputMode()) {
// 解锁键盘
mKeyguardLock.disableKeyguard();
}
}注意,这里使用的mWakelock.isHeld())来判断屏幕当前是否是休眠状态,从Android 2.1 API Level7开始增加了一个判断屏幕是否处于点亮状态可以使用public boolean isScreenOn ()这个方法。
锁屏幕的代码是
public void lockScreen() {
// release screen
if (!km.inKeyguardRestrictedInputMode()) {
// 锁键盘
mKeyguardLock.reenableKeyguard();
}
// 使屏幕休眠
if (mWakelock.isHeld()) {
mWakelock.release();
}
}
这里要注意,如果没有锁键盘而直接调用mWakelock.release()会产生一个异常。所以一定要先把键盘锁了然后再使屏幕休眠。来自:http://www.devdiv.com/thread-64416-1-1.html