我正在开发一个 android 应用程序,我想让主屏幕在来电时闪烁。我尝试在活动中调用以下 startblinking() 方法,屏幕闪烁正常。
但是,当我尝试在电话侦听器的 Ring 状态(在服务类中)调用相同的方法时,我收到以下错误,因为服务类没有窗口。
The method getWindow() is undefined for the type PhoneListener
.
private void startblinking()
{
Log.e("inside","blink MEthod");
timerforblinking.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
runOnUiThread(new Runnable()
{
public void run()
{
time = (float) (time + 0.5);
if(time == 0.5 || time == 1.5 || time == 2.5 || time == 3.5 || time == 4.5 || time == 5.5)
{
Log.e("time","OFF - time = "+time);
layoutParams.screenBrightness = (float) 30 / 255;
getWindow().setAttributes(layoutParams);
}
if(time == 1.0 || time == 2.0 ||time == 3.0 ||time == 4.0 ||time == 5.0 )
{
Log.e("time","ON - time = "+time);
layoutParams.screenBrightness = (float)255 / 255;
getWindow().setAttributes(layoutParams);
}
if(time >= 6.0)
{
layoutParams.screenBrightness = (float)255 / 255;
getWindow().setAttributes(layoutParams);
timerforblinking.purge();
timerforblinking.cancel();
}
}
});
}
}, 0, 500);
是否有可能的解决方法来实现来电时屏幕闪烁。
请帮忙。谢谢!