博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

public void onCreate(Bundle savedInstanceState) {

 final IntentFilter filter = new IntentFilter();  
        filter.addAction(Intent.ACTION_SCREEN_OFF);  
        filter.addAction(Intent.ACTION_SCREEN_ON);  
        registerReceiver(mBatInfoReceiver, filter);  

    } 

 

 private final BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {  
        @Override  
        public void onReceive(final Context context, final Intent intent) {  
            final 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...");  
   
           }  
        }  

    }; 

posted on 2012-06-26 14:41  Likwo  阅读(4519)  评论(0编辑  收藏  举报