public class myReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(final Context context, Intent recievedIntent) {
if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
wasScreenOn = false;
Intent intent = new Intent(context,
myActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
context.startActivity(intent
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
} else if (recievedIntent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
wasScreenOn = true;
}
}
}
呼叫操作屏幕后显示活动。
myActivity.class
使用KeyguardManager禁用Keyguard并启动服务。在服务中注册接收器。现在当用户关闭设备然后调用ACTION_SCREEN_OFF并点击主页按钮然后调用ACTION_SCREEN_ON但是当我按住home buttom多次时会出现问题。
答案 0 :(得分:0)
在接收器标签
中的清单中添加一行接收器android:name =“。MyBoardCast”android:enabled =“true”