Reputation:
Screen_Off does not work in application Level ,although it is working on Activity Level.
My Problem,when Screen goes off,it must go to Login screen,below code ,successfully go to Login screen but it cause me unregistered Receive Broadcast
what i have did
if l do in Menifesty level,Screen off broadcast does not fire,
Manifest Level
<receiver android:name="com.android.libray.ScreenReciver" android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter>
</receiver>
if i do in activity level,then it will fire screenReciver
IntentFilter filter =new IntentFilter(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver=new ScreenReciver();
registerReceiver(mReceiver, filter);
public class ScreenReciver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// do whatever you need to do here
Intent myintent = new Intent(context,TimerClockActivity.class);
myintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myintent);
wasScreenOn = false;
Log.v("screenoff", "Logggoff");
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
// and do whatever you need to do here
}
}
}
Upvotes: 1
Views: 340
Reputation: 82543
The SCREEN_OFF
Broadcast is a protected broadcast, and you will only receive it if you register dynamically through Java code in a Service or Activity or another Receiver. Registering in the manifest doesn't work for this broadcast.
Upvotes: 2