I want to find out that the screen is OFF when user locked a phone in android.I used BroadCast receiver like this and registered but I am not getting the screen is off or not
public class MyActivity extends Activity{
private static final String ACTION = "android.intent.action.ACTION_SCREEN_OFF";
BroadcastReceiver myReceiver;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
context = this;
final IntentFilter theFilter = new IntentFilter();
theFilter.addAction(ACTION);
context.registerReceiver(myReceiver, theFilter);
System.out.println("inside increate");
myReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("phone locked*****");
}
};
}}
How to find out this issue ?
Step #1: Delete the
private static final String ACTIONlineStep #2: Use
Intent.ACTION_SCREEN_OFFin youraddAction()line (or, better yet, just supply it to theIntentFilterconstructor and get rid of theaddAction()line)Step #3: Use
android.util.Loginstead ofSystem.out.println()