Screen off and on in android/Program that listens screen off in android/listening to screen on and off in android
package com.sample; import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.IBinder; public class ScreenAction extends Service{ @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); registerReceiver(mReceiver, filter); return super.onStartCommand(intent, flags, startId); } private BroadcastReceiver mReceiver= new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction()==Intent.ACTION_SCREEN_OFF){ } if(intent.getAction()==Intent.ACTION_USER_PRESENT){ } } }; } |
See more
Comments
Post a Comment