Screen_Off 在应用程序级别中不起作用,尽管它在活动级别上工作。
我的问题,当屏幕熄灭时,它必须进入登录屏幕,下面的代码,成功进入登录屏幕,但它导致我未注册接收广播
我做了什么
如果我在 Menifesty 级别做,屏幕关闭广播不会触发,
清单级别
<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
}
}
}