powermanager

AlarmManager working well in emulator but not in real device

冷暖自知 提交于 2019-12-02 08:13:13
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 onReceive(final Context context, Intent intent){ PowerManager pm = (PowerManager) context.getSystemService

Android有用代码片断(五)

隐身守侯 提交于 2019-12-01 13:36:25
不知不觉中,就收集了超过70条的自己感觉有意思的代码片段,分为三篇文章: android有用代码片段 、 Android有用代码片段(二) 、 Android有用代码片段(三)、 Android有用代码片段(四) 这三篇,今天,开始第五篇的整理!这里解释一下,因为一、二、三都是每个有20个片段,但是在四中,由于第70个代码过长,所以在第四篇中,只有10个片段。 七十一、android自动跳转 有些时候需要类似这样的功能,在一个页面停留2秒后,跳转到另外一个页面! 第一种方法: [java] view plain copy print ? Timer timer = new Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { // 你要干的活 } }; timer.schedule(timerTask, 1000 * 2 ); //2秒后执行 Timer timer = new Timer(); TimerTask timerTask = new TimerTask() { @Override public void run() { // 你要干的活 } }; timer.schedule(timerTask, 1000 * 2); //2秒后执行 在run(

What should I replace SCREEN_DIM_WAKE_LOCK with?

两盒软妹~` 提交于 2019-11-30 17:43:43
I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. However, SCREEN_DIM_LOCK has been depreciated. So, what should I be replacing it with? //Instance of wake lock for AlarmActivity PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock"); Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK should be replaced with FLAG_KEEP_SCREEN_ON . After doing a bit of digging, I turned up this... getWindow().addFlags(WindowManager.LayoutParams

Attempting to put Android device to sleep, but the PowerManager does not contain a "goToSleep(long) method

时光怂恿深爱的人放手 提交于 2019-11-30 09:23:39
问题 I am attempting to put a device to sleep and I have found references all over about using the PowerManager class's goToSleep(long) method but I do not see it in the documentation and it does not work when I attempt to using it in my code. Android's documentation does not contain a goToSleep method that I could see. My Code: private void sleepDevice() { try { PowerManager powerMgr = (PowerManager) getSystemService(Context.POWER_SERVICE); long time = 1000; powerMgr.goToSleep(time); } catch

What should I replace SCREEN_DIM_WAKE_LOCK with?

会有一股神秘感。 提交于 2019-11-30 01:22:41
问题 I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. However, SCREEN_DIM_LOCK has been depreciated. So, what should I be replacing it with? //Instance of wake lock for AlarmActivity PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock"); 回答1: Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK should be replaced with FLAG_KEEP

Reboot the phone on a button click

元气小坏坏 提交于 2019-11-27 08:44:04
I am making an Android app that needs to have the phone reboot or turn off when a button is clicked. Is this possible? Or will the phone require root access? Zelimir You can do that using android.os.PowerManager . Function reboot(String reason) is available, you need permission: android.permission.REBOOT Official site: http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String) Of course, you are likely to get that permission only if your application is signed with the system signing key: How to compile Android Application with system permissions I did this in

Reboot the phone on a button click

ε祈祈猫儿з 提交于 2019-11-26 17:47:13
问题 I am making an Android app that needs to have the phone reboot or turn off when a button is clicked. Is this possible? Or will the phone require root access? 回答1: You can do that using android.os.PowerManager . Function reboot(String reason) is available, you need permission: android.permission.REBOOT Official site: http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String) Of course, you are likely to get that permission only if your application is signed

PowerManagerService(一)

岁酱吖の 提交于 2019-11-26 16:51:52
极力推荐Android 开发大总结文章:欢迎收藏 程序员Android 力荐 ,Android 开发者需要的必备技能 PowerManagerService 提供Android系统的电源管理服务,主要功能是控制系统待机状态,屏幕显示,亮度调节,光线/距离传感器的控制等。 相关代码在以下文件中: frameworks/base/services/java/com/android/server/SystemServer.java frameworks/base/core/java/android/os/PowerManager.java frameworks/base/services/core/java/com/android/server/power/PowerManagerService.java frameworks/base/services/core/jni/com_android_server_power_PowerManagerService.cpp frameworks/base/core/java/android/os/PowerManagerInternal.java frameworks/base/services/core/java/com/android/server/power/Notifier.java device/qcom/common/power

PowerManagerService分析(四)之亮屏流程分析

瘦欲@ 提交于 2019-11-26 16:51:35
极力推荐Android 开发大总结文章:欢迎收藏 程序员Android 力荐 ,Android 开发者需要的必备技能 PowerManagerService 之前系列文章请参考如下 1. PowerManagerService分析(一)之PMS启动 2. PowerManagerService分析(二)之updatePowerStateLocked()核心 3. PowerManagerService分析(三)之WakeLock机制 注: 本文转自网络, 原文地址 本篇分析PMS中涉及到亮屏的部分,以及PMS相关的两个类: PowerManager 和 Notifier 。 1.亮屏流程 1.1.Power键亮屏 这里直接从 PhoneWindowManager 开始分析。按 power 键后,会触发 PhoneWindowManager 的 interceptKeyBeforeQueueing() 方法: @Override public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { ....... case KeyEvent.KEYCODE_POWER: { cancelPendingAccessibilityShortcutAction(); result &= ~ACTION_PASS

Check if battery optimization is enabled or not for an app

拈花ヽ惹草 提交于 2019-11-26 12:26:36
问题 Android 6 and 7 have some power optimizations (doze mode) which restrict app networking when device is not used. User may disable optimization mode for any app in Battery settings: Is it possible to check if optimization is enabled for my app or not? I need to ask user to disable optimization for better app functionality, but I don\'t know how to check it programatically. 回答1: This one was a bit tricky to track down: here's what you are looking for PowerManager.isIgnoringBatteryOptimizations(