ANDROID关于亮屏和暗屏还有解锁的监听事件http://blog.csdn.net/muskmelon123/article/details/7522023

转自:http://blog.csdn.net/muskmelon123/article/details/7522023


package com.lock.muskmelon;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class Lock8secondActivity extends Activity {

		public void onCreate(Bundle savedInstanceState) {   

		super.onCreate(savedInstanceState);   

		setContentView(R.layout.main);   
		
		
        final String TAG = null;
		
        
		
		final IntentFilter filter = new IntentFilter();  
        filter.addAction(Intent.ACTION_SCREEN_OFF);  
        filter.addAction(Intent.ACTION_SCREEN_ON); 
        filter.addAction(Intent.ACTION_USER_PRESENT); 
          
        final BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {  
            @Override  
            public void onReceive(final Context context, final Intent intent) {
            	

                String action = intent.getAction();  

                
               if(Intent.ACTION_SCREEN_ON.equals(action))
               {  
                    Log.d(TAG, "screen is on...");  
            	   
               }
               
               else if(Intent.ACTION_SCREEN_OFF.equals(action))
               {  
                    Log.d(TAG, "screen is off...");  
               }  
               
               else if(Intent.ACTION_USER_PRESENT.equals(action))
               {
            	   Log.d(TAG, "screen is unlock..."); 
               }
               
            }  
        };  
        
        registerReceiver(mBatInfoReceiver, filter);
		
		
		
	}   

} 


你可能感兴趣的:(ANDROID关于亮屏和暗屏还有解锁的监听事件http://blog.csdn.net/muskmelon123/article/details/7522023)