android 屏幕保护
来源:技术人生 责任编辑:栏目编辑 发表时间:2013-07-01 12:55 点击:次
首先,需要启动一个后台服务,用于注册一个BroadcastReceiver
这个BroadcastReceiver用于监听Intent.ACTION_SCREEN_OFF
这样在发生这个事件Intent.ACTION_SCREEN_OFF 也就是用户锁屏或者屏幕上锁时触发。
Service中注册BroadcastReceiver代码
view plaincopy to clipboardprint?
package com.pingbao;
import android.app.KeyguardManager;
import android.app.Service;
import android.app.KeyguardManager.KeyguardLock;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class ZyScreenService extends Service {
KeyguardManager mKeyguardManager = null;
private KeyguardLock mKeyguardLock = null;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
Log.i("in Service","in Service");
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = mKeyguardManager.newKeyguardLock("");
mKeyguardLock.disableKeyguard();
Log.i("in Service1","in Service1");
BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
try {
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClass(context, ZyScreenSaver.class);
context.startActivity(i);
// finish();
Log.i("BroadcastReceiver","B
package com.pingbao;
import android.app.KeyguardManager;
import android.app.Service;
import android.app.KeyguardManager.KeyguardLock;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
public class ZyScreenService extends Service {
KeyguardManager mKeyguardManager = null;
private KeyguardLock mKeyguardLock = null;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate()
{
// TODO Auto-generated method stub
super.onCreate();
}
@Override
public void onStart(Intent intent, int startId)
{
// TODO Auto-generated method stub
Log.i("in Service","in Service");
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock = mKeyguardManager.newKeyguardLock("");
mKeyguardLock.disableKeyguard();
Log.i("in Service1","in Service1");
BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
try {
Intent i = new Intent();
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setClass(context, ZyScreenSaver.class);
context.startActivity(i);
// finish();
Log.i("BroadcastReceiver","B
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>