How to get trigger that screen is locked or on in android?? i tried using SCREEN_OFF & SCREEN_ON action in broadcast receiver but it's not working.
public void onReceive(Context context, Intent intent) {
Log.d("XYZ", "Screen ON/OFF");
Toast.makeText(context, "screen",10000).show();
if(intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
.......
}
}
in activity i have registered broadcast like-
screen is object of my broadcast receiver
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mContext.registerReceiver(screen, filter);
Hey try using dynamic calling of broadcast,I tried this it will surly work...
Call the
UpdateService.class
within yourMainActivity.class
.startService(new Intent(MainActivity.this, UpdateService.class));
UpdateService.class
Receiver class