private void updateShowSeconds() { if (mShowSeconds) { // Wait until we have a display to start trying to show seconds. if (mSecondsHandler == null && getDisplay() != null) { mSecondsHandler = new Handler(); if (getDisplay().getState() == Display.STATE_ON) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); mContext.registerReceiver(mScreenReceiver, filter); } } else { if (mSecondsHandler != null) { mContext.unregisterReceiver(mScreenReceiver); mSecondsHandler.removeCallbacks(mSecondTick); mSecondsHandler = null; updateClock(); } } } private final BroadcastReceiver mScreenReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (Intent.ACTION_SCREEN_OFF.equals(action)) { if (mSecondsHandler != null) { mSecondsHandler.removeCallbacks(mSecondTick); } } else if (Intent.ACTION_SCREEN_ON.equals(action)) { if (mSecondsHandler != null) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } } } }; private final Runnable mSecondTick = new Runnable() { @Override public void run() { if (mCalendar != null) { updateClock(); } mSecondsHandler.postAtTime(this, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } }; } 编译报错,lframeworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/clock.java:115: cannot findlsymbolsymbol method getstate()location: class android.view.Display if (getDisplay().getstate() == Display.STATE_ON) fframeworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/clock.java:115: cannot findlsymbolsymbol : variable STATE_ONlocation: class android.view.Display if (getDisplay().getstate() == Display.STATE_ON) fNote: Some input files use or override a deprecated API.Note: Recompile with -xlint:deprecation for details.Note: Some input files use unchecked or unsafe operations.Note: Recompile with -xlint:unchecked for details.2 errorsmake: *** fout/target/common/obi/Apps/SvstemlT intermediates/classes-full-dehun iarl Frror 4l
时间: 2024-04-07 07:32:32 浏览: 206
根据报错信息,可能是因为没有找到 `getstate()` 方法和 `STATE_ON` 变量,这可能是因为你的代码中没有正确引入 `android.view.Display` 类。你可以尝试在代码开头添加以下引入语句:`import android.view.Display;`。另外,你的代码中也存在一些过时的 API 和未检查或不安全的操作,建议使用 `-xlint:deprecation` 和 `-xlint:unchecked` 对代码进行重新编译,以获取更详细的错误信息。
相关问题
private void updateShowSeconds() { if (mShowSeconds) { WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int state = display.getState(); // Wait until we have a display to start trying to show seconds. if (mSecondsHandler == null && display != null) { mSecondsHandler = new Handler(); if (state == Display.STATE_ON) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); mContext.registerReceiver(mScreenReceiver, filter); } } else { if (mSecondsHandler != null) { mContext.unregisterReceiver(mScreenReceiver); mSecondsHandler.removeCallbacks(mSecondTick); mSecondsHandler = null; updateClock(); } } }Android4.4 编译display.getState()报错
在Android 4.4中,`getState()`方法是在`Display`类中被添加的,因此该方法仅适用于API级别21及更高版本的Android。如果您在Android 4.4中使用`getState()`方法,编译器会报错。
如果您需要在Android 4.4中使用此功能,您可以考虑使用其他方法替代,例如检查屏幕是否亮着。您可以使用以下代码来检查屏幕状态:
```
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = powerManager.isScreenOn();
```
请注意,此方法仅检查屏幕是否亮着,并不提供更详细的屏幕状态信息。如果您需要更详细的信息,请考虑升级到更高版本的Android。
private void updateShowSeconds() { if (mShowSeconds) { // Wait until we have a display to start trying to show seconds. if (mSecondsHandler == null && getDisplay() != null) { mSecondsHandler = new Handler(); if (getDisplay().getState() == Display.STATE_ON) { mSecondsHandler.postAtTime(mSecondTick, SystemClock.uptimeMillis() / 1000 * 1000 + 1000); } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); mContext.registerReceiver(mScreenReceiver, filter); } } else { if (mSecondsHandler != null) { mContext.unregisterReceiver(mScreenReceiver); mSecondsHandler.removeCallbacks(mSecondTick); mSecondsHandler = null; updateClock(); } } } Android4.4 编译display.getState()报错,getDisplay().getState(,使用getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay().getState()也不行
在Android 4.4中,`getState()`方法是在`Display`类中被添加的,因此该方法仅适用于API级别21及更高版本的Android。如果您在Android 4.4中使用`getState()`方法,编译器会报错。
使用`getSystemService(Context.WINDOW_SERVICE).getDefaultDisplay()`获取`Display`对象,然后调用`getState()`方法也不起作用,因为在Android 4.4中,`getState()`方法仍然是在`Display`类中被添加的。
如果您需要在Android 4.4中使用此功能,您可以考虑使用其他方法替代,例如检查屏幕是否亮着。您可以使用以下代码来检查屏幕状态:
```
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = powerManager.isScreenOn();
```
请注意,此方法仅检查屏幕是否亮着,并不提供更详细的屏幕状态信息。如果您需要更详细的信息,请考虑升级到更高版本的Android。
阅读全文