Posts

Showing posts from May, 2017

Detecting shut down and reboot in android

Hi, Have a great day frnds.. Now we going to look up the detecting shut down and reboot events in android. Here is the code: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ShutDownReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {             Log.i("event", "shutdown");         } else if (intent.getAction().equals(Intent.ACTION_REBOOT)) {             Log.i("event", "reboot");         }     } } Then apply in your activity, shutDownReceiver = new ShutDownReceiver(); filter.addAction(Intent.ACTION_REBOOT); filter.addAction(Intent.ACTION_SHUTDOWN); @Override     protected void onPause() {         super.onPause(); unregisterReceiver(shutDownReceiver); } @Override     protected void onResume(

Detecting Screen on and Screen Off via services

Hi buddies, have a happy Sunday. Today I'll explore about detecting screen on and screen off in android devices. I got your mind, can use also by Broad cast Receivers. Yes, you can. But how do you know, if app goes offline and screen off. First write the Broad cast receiver class for receiving results. ScreenReceiver.Java -------------------------- import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class ScreenReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {             screenOff = true;             Log.i("screenLog", "screen off");         } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {             screenOff = false;             Log.i("screenLog", "screen on");         }     } } Then write