alarmmanager

Wake phone from unlock screen android

孤街醉人 提交于 2019-12-22 10:28:31
问题 Hеllo guуs, I want to unlock the phone with service. I'm using alarm manager. Receiver and Service were added to manifest and also permissions for RECEIVE_BOOT_COMPLETE and WAKE_LOCK AlarmReceiver public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { setAlarms(context); } public static void setAlarms(Context context) { cancelAlarms(context); PendingIntent pIntent = createPendingIntent(context); Calendar calendar = Calendar

AlarmManager Interval for Android

雨燕双飞 提交于 2019-12-22 10:26:35
问题 This is the code I have so far AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); setRepeatingAlarm(); public void setRepeatingAlarm() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 10); Intent intent = new Intent(this, TimeAlarm.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), (15 * 1000), pendingIntent); } } This is

Is it possible to call onReceive method from a dialog?

霸气de小男生 提交于 2019-12-22 10:06:27
问题 I have a custom dialog with editText and save button . When button clicked, I want it call MyReceiver . But the log and Toast in MyReceiver never get displayed. Reminder final AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View promptView = getLayoutInflater().inflate(R.layout.dialog_with_edittext, null); Button save = (Button) promptView.findViewById(R.id.okBtn); final EditText task = (EditText) promptView.findViewById(R.id

Service or IntentService or AlarmManager approach

天大地大妈咪最大 提交于 2019-12-22 09:58:38
问题 I am building a game-like application and I've been reading about all the different approaches of running things with Services in background, foreground, Alarms and so on, and I am a bit confused. My app would go like this (example): user presses a button in Main, then he can close the app after 30 minutes Activity1 opens up user finishes whatever he needs to do in that activity, which triggers the next activity to start after 2 hours after 2 hours Activity2 opens up user finishes whatever he

Does AlarmManager require the PendingIntent to be of Type BroadcastReceiver?

眉间皱痕 提交于 2019-12-22 09:24:21
问题 The documentation for AlarmManager seems to imply (but does not outright explicitly require) that the PendingIntent you pass in to any of the set() methods should be of the type BroadcastReceiver, but I tested passing in other component types (like an IntentService) and it seemed to work fine. Is it safe to use non-BroadcastReceiver Intents with AlarmManager? 回答1: Yes, and it has always worked, but I suspect not in the way that you're thinking. You can use any PendingIntent with an alarm;

Android闹钟设置的解决方案

﹥>﹥吖頭↗ 提交于 2019-12-22 05:51:25
Android设置闹钟并不像IOS那样这么简单,做过Android设置闹钟的开发者都知道里面的坑有多深。下面记录一下,我解决Android闹钟设置的解决方案。 主要问题 API19开始AlarmManager的机制修改。 应用程序被Kill掉后,设置的闹钟不响。 6.0以上进入Doze模式会使JobScheduler停止工作。 手机设置重启后,闹钟失效问题。 API19以上AlarmManager机制的修改 API19之前AlarmManager提供了三个设置闹钟的方法,由于业务需求闹钟只需要一次性,所以采用set(int type,long startTime,PendingIntent pi);这个方法。 从API 19开始,AlarmManager的机制都是非准确传递,操作系统将会转换闹钟,来最小化唤醒和电池使用。 由于之前的程序,没有对API19以上的闹钟设置做处理,导致在4.4以上的手机设置闹钟无响应(应用程序没有被杀死的情况也没有闹钟)。 因些,设置闹钟需要根据API的版本进行分别处理设置。代码如下: 1 AlarmManager am = (AlarmManager) getActivity() 2 .getSystemService(Context.ALARM_SERVICE); 3 if (Build.VERSION.SDK_INT >= Build

Android之AlarmManager(全局定时器/闹钟)指定时长或以周期形式执行某项操作

删除回忆录丶 提交于 2019-12-22 05:51:13
1、AlarmManager,顾名思义,就是“提醒”,是Android中常用的一种系统级别的提示服务,可以实现从指定时间开始,以一个固定的间隔时间执行某项操作,所以常常与广播(Broadcast)连用,实现闹钟等提示功能 2、AlarmManager的常用方法有三个: (1) set(int type,long startTime,PendingIntent pi); 该方法用于设置一次性闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟执行时间,第三个参数表示闹钟响应动作。 (2) setRepeating(int type,long startTime,long intervalTime,PendingIntent pi); 该方法用于设置重复闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟首次执行时间,第三个参数表示闹钟两次执行的间隔时间,第三个参数表示闹钟响应动作。 (3) setInexactRepeating(int type,long startTime,long intervalTime,PendingIntent pi); 该方法也用于设置重复闹钟,与第二个方法相似,不过其两个闹钟执行的间隔时间不是固定的而已。 3、三个方法各个参数详悉: (1) int type: 闹钟的类型,常用的有5个值:AlarmManager.ELAPSED_REALTIME

在android下实现定制闹钟

纵饮孤独 提交于 2019-12-22 05:51:03
闹钟是我们生活中常用的工具。在android系统中提供了强大的闹钟接口,并且使用起来也非常简单。AlarmManager是android提供的闹铃管理接口。我们想创建一个闹铃程序就需要通过它来完成。那么接下来就看一下创建闹钟的过程: 1. 获取AlarmManager对象 AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 在android中获取系统服务的方式就是getSystemService(ServiceCode)。 2. 为AlarmManager建立一个receiver类,这个类是用来接收广播的闹铃事件的,我们也可以看作是闹铃的处理程序吧。 public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "This the time", Toast.LENGTH_LONG).show(); } } 这个类需要继承自BroadcastReceiver类,这里有两种方式来接收Intent的广播事件,一是动态注册一个Receiver

Android闹钟 AlarmManager的使用

岁酱吖の 提交于 2019-12-22 05:50:46
Android闹钟 AlarmManager的使用 AlarmManager介绍    AlarmManager 这个类提供对系统闹钟服务的访问接口。   你可以为你的应用设定一个在未来某个时间唤醒的功能。   当闹钟响起,实际上是 系统发出了为这个闹钟注册的广播 ,会自动开启目标应用。   注册的闹钟在设备睡眠的时候仍然会保留,可以选择性地设置是否唤醒设备,但是 当设备关机和重启后,闹钟将会被清除 。   在alarm的receiver的 onReceive() 方法被执行的时候,Alarm Manager持有一个 CPU唤醒锁 ,这样就保证了设备在处理完广播之前不会sleep。   一旦onReceive()方法返回,Alarm Manager就会释放这个锁,表明一些情况下可能onReceive()方法一执行完设备就会sleep。   如果你的alarm receiver中调用了 Context.startService() ,那么很可能service还没起来设备就sleep了。   为了阻止这种情况,你的BroadcastReceiver和Service需要实现不同的唤醒锁机制,来确保设备持续运行到service可用为止。    注意 :Alarm Manager主要是用来在特定时刻运行你的代码,即便是你的应用在那个特定时刻没有跑的情况。    对于常规的计时操作(ticks

AlarmManager实现闹钟功能

本秂侑毒 提交于 2019-12-22 05:50:32
一:AlarmManager简介 1、AlarmManager,顾名思义,就是“提醒”,是Android中常用的一种系统级别的提示服务,可以实现从指定时间开始,以一个固定的间隔时间执行某项操作,所以常常与广播(Broadcast)连用,实现闹钟等提示功能 2、AlarmManager的常用方法有三个: (1)set(int type,long startTime,PendingIntent pi); 该方法用于设置一次性闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟执行时间,第三个参数表示闹钟响应动作。 (2)setRepeating(int type,long startTime,long intervalTime,PendingIntent pi); 该方法用于设置重复闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟首次执行时间,第三个参数表示闹钟两次执行的间隔时间,第三个参数表示闹钟响应动作。 (3)setInexactRepeating(int type,long startTime,long intervalTime,PendingIntent pi); 该方法也用于设置重复闹钟,与第二个方法相似,不过其两个闹钟执行的间隔时间不是固定的而已。 3、三个方法各个参数详悉: (1)int type:闹钟的类型,常用的有5个值:AlarmManager.ELAPSED