Android turn screen on and off

Android: Как программно включать и выключать экран?

Прежде чем пометить этот пост как «дублирующий», я пишу его, потому что никакое другое сообщение не содержит решения проблемы.

Я пытаюсь выключить устройство, затем через несколько минут или смены датчика снова включаю.

Отключить тесты дисплея

Я могу выключить экран, используя:

Мне не удалось выключить экран с помощью метода wl.release ().

Включите тест дисплея

Моя первая догадка, как следует, не работает. Ничего не происходит, экран остается выключенным.

Я также попытался использовать wakelocks, но безуспешно.

Наконец, я попробовал следующее, но безрезультатно.

В общем, я не получаю никаких ошибок в консоли ни для одного из этих методов. Мой тестовый текст «Экран должен быть включен» появляется на экране, когда я включаю устройство с помощью кнопки питания. Это показывает, что код должен был работать. Пожалуйста, отвечайте только в том случае, если вы протестировали код, похоже, что многие функции, такие как params.screenBrightness = -1 , не работают должным образом согласно sdk.

Я предполагаю, что вы хотите, чтобы это действовало только тогда, когда ваше приложение находится на переднем плане.

Не выключает экран в традиционном понимании. Это делает экран максимально тусклым. В стандартной платформе есть ограничение на то, насколько тусклым он может быть; Если ваше устройство действительно позволяет экрану полностью отключиться, то это некоторая особенность реализации этого устройства, а не поведение, на которое вы можете рассчитывать на разных устройствах.

Фактически, использование этого в сочетании с FLAG_KEEP_SCREEN_ON означает, что вы никогда не позволите экрану выключиться (и, следовательно, устройству перейти в режим низкого энергопотребления), даже если конкретное устройство позволяет вам установить яркость экрана на полную. Имейте это в виду. Вы будете использовать гораздо больше энергии, чем если бы экран был действительно выключен.

Теперь, чтобы вернуть экран к нормальной яркости, достаточно установить значение яркости:

Я не могу объяснить, почему это не заменит ранее установленное вами значение 0. В качестве теста вы можете попробовать установить принудительную полную яркость, чтобы добиться этой конкретной яркости:

Это определенно работает. Например, приложения Google Книги используют это, чтобы вы могли настроить яркость экрана на затемнение при использовании книги, а затем вернуться к обычной яркости при выключении.

Чтобы облегчить отладку, вы можете использовать «adb shell dumpsys window», чтобы увидеть текущее состояние вашего окна. В данных для вашего окна он сообщит вам текущие LayoutParams, которые были установлены для него. Убедитесь, что ценность, которую вы думаете, действительно существует.

И снова FLAG_KEEP_SCREEN_ON — это отдельная концепция; он и яркость не влияют друг на друга напрямую. (И не было бы причин снова устанавливать флаг при отмене яркости, если вы уже установили его при установке яркости на 0. Флаг останется установленным, пока вы его не измените.)

Источник

3 Ways to Stop Android Phone Screen From Turning Off Automatically

How many times it happened to you when you try to read something on your phone and the screen goes off? Screen timeout is the setting on your phone which automatically turns off the display in order to save the battery. Since Android phones are completely customizable this setting also has some options to choose from, and on some phones, you can even completely turn it off. So, here I am telling you the ways to stop the phone screen from turning off. Read on!

Stop Phone Screen from Turning off Completely

Table of Contents

If you want to completely turn off this setting then there is an option in the display setting. If you don’t find the option to turn it off, don’t worry we have another trick up our sleeve to tell you about.

Читайте также:  Фпс ап таймсус самп андроид

1. Via Display Settings

1. Pull down the notification panel and tap the little setting icon to go to Settings.
2. In the Settings menu, go to the Display and look for the Screen Timeout settings.

3. Tap the Screen Timeout setting and select the duration you want to set or just select “Never” from the options.

If you won’t see the Never option in the settings but you still want to keep your device awake for longer then follow the next method.

2. Via Developer Options

1. Go to Settings > About Phone > tap on Build Number 7 times.
2. Navigate back to Settings > System > Developer Options.
3. Look for Stay Awake option and enable it.

Now while your phone is on charging, the screen will not turn off automatically unless you remove the charger. In that case, the default setting will enable which you selected in the display setting.

3. Via Third-party Apps

You can also prevent your phone screen from turning off completely using a third-party app. There are plenty of such apps available on the Play Store, and we are using “Caffeine”. Here’s how to use it:

1. Download and install Caffeine – Keep Screen On from the Play Store.

2. The app works via a toggle, so you will need to add this to the Quick Settings panel.

3. Pull down the Quick Settings panel and tap on the Pencil icon to edit it.

4. Now look for the Coffee Mug icon among all quick settings.

5. Move this “Caffeine” toggle to the Quick Settings panel by holding and dragging it.

7. When the toggle is in the main Quick Settings panel, you can use it anytime.

Whenever you want to change the screen timeout time, swipe down to open the Quick Settings, and tap the Coffee Mug icon. By default, it sets screen timeout to Infinite, but it also has a number of other customization options.

Wrapping up

This is how you can make your smartphone screen never go off while you are reading something important on it. Tell us in the comments, which of the above-mentioned ways will you use to increase screen timeout on your phone.

For more Android tips and tricks, stay tuned.

You can also follow us for instant tech news at Google News or for tips and tricks, smartphones & gadgets reviews, join GadgetsToUse Telegram Group or for the latest review videos subscribe GadgetsToUse Youtube Channel.

Источник

How to Turn Off Phone without Power Button (Android)

Nobody needs a tutorial to learn how one can turn a phone on or off. However, if the Power button or the screen of your device is broken or not functioning for some reason, you might end up looking for a guide like this. In this tutorial, we’ll be exploring all possible ways to restart and turn off an Android phone or tablet without the power button or the volume buttons. If you want to just wake up your phone’s screen and make it sleep without the power button, read my tutorial.

The power button of a phone might break or stop being responsive due to an accidental drop, overuse, mishandling, poor build quality. If you have been using your phone or tablet for many years, the power button may become non-functional. The ultimate solution to this hardware problem is to visit a service center to get it fixed. Alternatively, you can use one of the tips given below to turn off your phone without the power button. Whether you own a phone from Samsung, Xiaomi, Oppo, OnePlus, Vivo, Realme, Nokia, or any other Android device, these tips will work on all Android devices.

Turn Off Phone without Power Button

There are several ways to power off an Android phone or tablet if power the button is broken. The tips will also help you restart the phone without the power button and volume button.

  • Using an ADB command
  • Via Android Accessibility Menu
  • Using a reboot app
  • Via Quick Settings menu (Samsung devices)
Читайте также:  Андроид чем восстановить бэкап

Before you learn to turn off your Android device, don’t forget to check out my detailed article describing 8 ways to turn on an Android phone without the power button.

ADB Command to Turn Off Phone

I won’t say that it’s the most convenient method to turn off Android devices when the power button is broken or the screen is damaged. However, it is possible to switch off and reboot an Android phone or tablet into Safe Mode, System Mode, Bootloader Mode, or Recovery Mode using ADB commands without using the Power and Volume keys.

To be able to run ADB commands on your Android device, you’ll need a laptop or PC. One more thing, USB debugging must be enabled on your device. Anyway, let’s see how to switch off an Android phone without the Power button and volume button.

  1. Download the latest Android SDK Platform-tools for Windows, or set up ADB and Fastboot on macOS.
  2. Enable USB debugging on your Android device if you don’t have it enabled already. You might not be able to do this if your phone’s touch screen is not working.
  3. Launch the Windows Command Prompt or Mac Terminal.
  4. Connect your device to your computer via a compatible USB cable.
  5. Issue the following command to ensure that your phone and computer are connected properly.
  6. Now, execute the following ADB command to turn off your Android phone. Here, ‘p‘ stands for ‘power off’.

  • Your Android device will power off without using the Power button.
  • In case you just want to restart your phone without using the power button, you can use the following command.
  • The ADB method can allow you to switch off your phone when the touch is not working.

    ADB Command to Power Off Android via Power Menu

    ADB commands can be a great help in certain tricky situations. You can trigger the long-press Power menu on your Android phone or tablet using ADB Shell commands.

    Just launch the command window, connect your phone to the computer and execute the following command:

    This will make the Android Power menu appear and you can then select the Power Off or Reboot option as per your choice.

    Power Off Android via Accessibility Menu

    All Android devices have a set of Accessibility settings to help physically and visually impaired people. Among the key features of Android’s Accessibility are Talkback and Accessibility or Assistant Menu. By enabling this menu, you can add an Accessibility shortcut in the navigation bar of your Android phone or tablet or get a floating menu icon. You can enjoy quick shortcuts to launch Google Assistant, Recents, Power Menu, Screenshots, and so on simply by tapping the Accessibility Menu icon.

    Let’s see how we can turn off an Android phone or tablet without the Power button via Accessibility Menu.

    1. Open Settings on your Android device and tap on Accessibility. On the devices from Chinese OEMs like Xiaomi, Vivo, Oppo, OnePlus, Realme, Huawei, etc., you’ll find Accessibility under Additional settings.
    2. If you own a Samsung Galaxy phone or Tab, select Interaction and dexterity and tap on the toggle icon in front of the Assistant menu. A floating icon for the Assistant menu will appear on the screen as shown below. If you find that floating icon irritating, you can change its size, appearance location, etc. by tapping on the Assistant menu option.
    3. Just tap on the floating Assistant menu icon to access the Power off menu. You can now turn off your Samsung Galaxy device without using the Power button.
    4. If you have a phone from Xiaomi, Redmi, Vivo, Oppo, OnePlus, Realme, or Huawei, you are supposed to enable the Accessibility menu from Accessibility. As soon as you enable it, the Accessibility menu icon will appear on the navigation bar. Just tap it to access the option to Power off your phone without using the Power button.
    Читайте также:  Wise disk cleaner android

    Turn off Android Phone Using Apps

    The Google Play Store is overloaded with apps for everything. You can find hundreds of apps that can let your power off and reboot a phone with a broken Power button. All such apps require either Accessibility permission or root privilege and offer similar options like the Accessibility menu shown above.

    I tested some of the most rated and popular apps that offer the option to turn off and reboot Android devices without pressing the Power key. Below, I am going to list the ones that are worth a try.

    Phone Lock + Volume Control (OFF+)

    Phone Lock + is a minimal app with no regular user interface as most apps have. Nonetheless, the app does its job and doesn’t require root.

    When Phone Lock is installed on your device, launch it from the app drawer. It’ll prompt you to select one of the 2 lock modes. Make your choice and grant Accessibility permission to the app when asked to do so. Now, whenever you want to access the Power Menu to switch off or restart your phone, just tap and hold the Phone Lock app icon. Please note that just taping the app icon will lock your device either immediately or after 5 seconds.

    Power Menu: Software Power Button

    Power Menu is another simple app that lets you launch the Power Menu with a single tap without holding the Power button. Of course, it will ask you to grant Accessibility permission under Installed Services for the first time.

    Assistive Touch for Android

    If you prefer to have a persistent floating button to access the Power Menu and lots of other things quickly without using the Power button, volume buttons, and the navigation bar keys, Assistive Touch for Android is a great option for you.

    Just tap on the floating touch icon and tap on the Power menu icon to turn off your Android phone or tablet if the Power button is broken or not working. One thing that I hate about this app is that it has too many irritating ads.

    Turn off Phone via Quick Settings (Samsung)

    Well, older Samsung devices didn’t have it, but if you have a Samsung Galaxy phone or Tab released in 2019 or later, you must have seen the Power Menu icon located in the Quick Settings screen. Phones like Galaxy Note 10, Note 20, Galaxy S10, S20, Galaxy A70, Galaxy A51, etc., have this shortcut.

    You can tap on the Power Menu icon to select the option to reboot or turn off your Samsung Galaxy device without the Power button.

    Turn off Samsung Device via Bixby

    Samsung Galaxy users can also turn off their phone without using the Power key using a Bixby voice command. I tried this using Google Assistant commands a well but it did not work.

    Launch Samsung Bixby and use “Turn off/Power off the phone” command. Bixby will ask you to select the Power off option. Just tap on it to shut down your Samsung device.

    Schedule Power Off Time via Android Settings

    Another way to turn off an Android phone without the Power button is by scheduling the power-off time via your device settings.

    1. Open Settings on your device.
    2. Tap the Search icon or bar on the settings menu page and type “schedule” in it.
    3. You’ll get a list of items that can be scheduled. Tap on Schedule power on/off.
    4. On the next page, you can set the time when you want to power on or off your Android device automatically without using the Power key.

    That’s all for now about turning off an Android device when the Power button is broken, the screen is black and the touch is not working. I hope the tips given here will also let you restart the phone without the power button. If you think I have missed any working method, please let me know.

    Источник

    Оцените статью