Skip to main content

Posts

Showing posts with the label display screen off

Screen off and on in android

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 , fil

Lock/unlock android phone programatically

Lock and unlock phone in android programmatically/ Lock phone using power manager/wave lock in android/Turn screen off in android/Display screen off in android To turn screen on in android, use the code below powermanager =  ((PowerManager) context .getSystemService(Context. POWER_SERVICE ));                   wakeLock = powermanager .newWakeLock(PowerManager. SCREEN_BRIGHT_WAKE_LOCK | PowerManager. ACQUIRE_CAUSES_WAKEUP , "tag" );             wakeLock . acquire (); To lock or to turn off display screen off, use the code below       if ( wakeLock .isHeld())             {                   wakeLock .release();             } Also set permission in Android manifest file  < uses-permission android:name = "android.permission.WAKE_LOCK" /> See more Block incoming calls Answer incoming calls Screen off and on in android Disable home button