powermanager

isPowerSaveMode() always returns false for Huawei devices

∥☆過路亽.° 提交于 2021-02-07 05:18:18
问题 I am currently implement a feature where the users are requested to ignore battery optimisation for the application. The reason for doing so, is that the main functionality of the application is unfortunately drastically affected by power save mode. To achieve my goal, I prompt the users by creating an Intent and setting the Action to ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Although, before firing the Intent , I both check for isPowerSaveMode() and isIgnoringBatteryOptimizations() to

isPowerSaveMode() always returns false for Huawei devices

点点圈 提交于 2021-02-07 05:16:54
问题 I am currently implement a feature where the users are requested to ignore battery optimisation for the application. The reason for doing so, is that the main functionality of the application is unfortunately drastically affected by power save mode. To achieve my goal, I prompt the users by creating an Intent and setting the Action to ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Although, before firing the Intent , I both check for isPowerSaveMode() and isIgnoringBatteryOptimizations() to

PowerManager.WakeLock on Android Devices

和自甴很熟 提交于 2020-01-14 10:46:48
问题 i am trying to implement an WakeLock in my Android App. I have the following code in my onCreat(): pm = (PowerManager) getSystemService(Context.POWER_SERVICE); myWakeLock = pm.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,"WakeLock for Tuner"); The second line leading to a crash. It throws a Fatal Exception. As far as I can see Android says that the first Argument is no valid wake lock level. But on the developer Site it is recommended to use FLAG_KEEP_SCREEN_ON so i am a litte

PowerManagerService第三讲之灭屏

老子叫甜甜 提交于 2020-01-13 05:05:33
一.灭屏简述 先来讲灭屏,灭屏的方式一般有如下几种: 1.用户按Power键灭屏; 2.手机自动放置一段时间后超时灭屏; 3.Sensor灭屏。 灭屏的原因在PowerManager类中的sleepReasonToString方法有列出常见的: /** * @hide */ public static String sleepReasonToString ( int sleepReason ) { switch ( sleepReason ) { case GO_TO_SLEEP_REASON_APPLICATION : return "application" ; case GO_TO_SLEEP_REASON_DEVICE_ADMIN : return "device_admin" ; case GO_TO_SLEEP_REASON_TIMEOUT : return "timeout" ; case GO_TO_SLEEP_REASON_LID_SWITCH : return "lid_switch" ; case GO_TO_SLEEP_REASON_POWER_BUTTON : return "power_button" ; case GO_TO_SLEEP_REASON_HDMI : return "hdmi" ; case GO_TO_SLEEP_REASON

AlarmManager working well in emulator but not in real device

不问归期 提交于 2019-12-31 06:20:14
问题 this is my code for setting alarm: public void SetAlarm(Context context, int tag, long time){ AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, Alarm.class); i.putExtra("position", tag); PendingIntent pi = PendingIntent.getBroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute } this is my onRecieve methode: public void

Turn the screen in to totally dark when press the button on the screen

本秂侑毒 提交于 2019-12-25 02:46:44
问题 How to code the android to turn the screen completely off just like you press the power button to lock your screen. I want the user to press the button on the screen and then screen goes off. I have tried (with permission): PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag"); wl.acquire(); but not working for me, please help! thank you! 来源: https://stackoverflow.com/questions/23432552/turn-the-screen-in-to-totally-dark

Turning screen on and off programmatically not working on some devices

好久不见. 提交于 2019-12-23 01:45:16
问题 I use the code below to turn the screen on and off. Both pieces of code work on most devices (tested on Galaxy Note, Galaxy S2, etc. etc.) but don't work on a few (mostly tablets but some phones as well). On some devices screen on works but screen off doesn't, and the opposite holds for some other devices. I'm not sure what the cause is since it's pretty standard code (and since it works on some devices that means triggering these functions i.e. the function call, is not a problem). Are there

Android ACTION_SHUTDOWN Broadcast not working

女生的网名这么多〃 提交于 2019-12-17 06:14:30
问题 Code - public class ShutdownReceiver extends BroadcastReceiver { private static final String TAG = "ShutdownReceiver"; @Override public void onReceive(final Context context, final Intent intent) { Logger.i(TAG, "Shutting Down.........................."); if("android.intent.action.ACTION_SHUTDOWN".equals(intent.getAction())) { //Power Off } } } Service - private BroadcastReceiver mReceiver = null; @Override public void onCreate() { super.onCreate(); // INITIALIZE RECEIVER //It is used to

How to change screen brightness?

风格不统一 提交于 2019-12-08 13:42:28
问题 How I can change screen brightness in Android? I can find how to do this for application, but I want do it for all system and permanently (until user changes it in options). I don't need to set it for custom value. Just low brightness level, Medium brightness and Maximum will be perfect. It is possible for example with PowerManager or something like that \? Using Android 2.0+. 回答1: WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness = <value from 0 to 1>;

How to bring application from background to foreground via BroadcastReceiver

狂风中的少年 提交于 2019-12-08 01:38:46
问题 I have two classes which are MainActivity and MyBroadcastReceiver. BroadcastReceiver detects whether phone screen is on or off. My desire is to launch my application whenever screen lock is released. I mean that I want to bring my application to the front when phone lock releases. Here is my activity class: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);