当手机正在睡觉时,我希望有一个动画活动(很像手机铃声动画)。
我已经阅读了许多关于使用WindowManager标志打开屏幕的帖子,所以我所做的就是将这段代码添加到我的activity的onCreate()函数中:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);
setContentView(R.layout.act_image_activity);
startAnimation();
}
我的问题是:
有人可以告诉我如何在屏幕开启后立即显示我的动画活动,并在完成后立即关闭屏幕?
答案 0 :(得分:0)
但这个接收器到你的清单
<receiver android:name="IntentReceiver" >
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" ></action>
<action android:name="android.intent.action.SCREEN_OFF" ></action>
</intent-filter>
</receiver>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context arg0, Intent arg1) {
Log.v("tag", "screen on");
// You can catch screen on here and start your animation
}
}, new IntentFilter(Intent.ACTION_SCREEN_ON));
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context arg0, Intent arg1) {
Log.v("tag", "screen off");
// You can catch screen off here and start your animation
}
}, new IntentFilter(Intent.ACTION_SCREEN_OFF));
}
答案 1 :(得分:0)
至于最初的延迟和看到一部分键盘,我认为没有办法防止这种情况发生。但是,您可以通过拨打PowerManager.goToSleep强制屏幕关闭。