alarmmanager

Set Repeated alarm at specific time every day

流过昼夜 提交于 2019-11-30 18:12:47
问题 I try to use alarm manager to run alarm at specific time every day. I am using this code Intent intent = new Intent(AlarmSettings.this, AlarmService.class); intent.putExtra("i", i); PendingIntent mAlarmSender = PendingIntent.getService(AlarmSettings.this, Id, intent, 0); AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),Calendar.getInstance().getTimeInMillis()+(24*60*60*1000), mAlarmSender);} the problem was in if

AlarmManager, BroadcastReceiver and Service not working

心已入冬 提交于 2019-11-30 17:41:01
I'm refactoring some code so that my app will pull data from a website once a day at a given time. From my research, it seems like AlarmManager is the most appropriate approach. The tutorial I have been following is: http://mobile.tutsplus.com/tutorials/android/android-fundamentals-downloading-data-with-services/ So far, AlarmManager and the BroadcastReceiver seem to be working, however the Service never seems to start (ie. onStartCommand doesn't seem to be called) Here are the important snippets of the code I have so far: MyActivity.java private void setRecurringAlarm(Context context) {

How to Cancel AlarmManager on a Scheduled time

随声附和 提交于 2019-11-30 16:45:05
How can I cancel one AlarmManager on a scheduled time, which was already started. I am starting one AlarmManager like this. I want to cancel it after 5 hours. How can I do this? AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, MyStartServiceReceiver.class); PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 30); service.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), REPEAT_TIME, pending); set

Simple AlarmManager example for firing an activity in 10 minutes

僤鯓⒐⒋嵵緔 提交于 2019-11-30 15:50:41
问题 I've found many similar questions to this, but they're too complicated (too much code), at least I think. Can this thing be done in a few code of lines? I want to fire an activity in 10 (let's say) minutes, that's it. Thank you. 回答1: To Set Alarm for 10 Minutes(let's say) Use this code AlarmManager alarmMgr = (AlarmManager)getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, ShortTimeEntryReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent,

AppWidgetProvider problem

人盡茶涼 提交于 2019-11-30 15:47:25
I have an AppWidgetProvider, and I need to do some initialization when a widget is first added to the home screen. I understand that the place to do it is in the onEnabled(Context context) method. My Problem is that this method is never called (As far as I can see in the logcat). Here is my code: public class MyMonitorWidget extends AppWidgetProvider{ @Override public void onEnabled(Context context) { super.onEnabled(context); Log.v("LOG", "Widget onEnabled"); Intent intentToFire = new Intent(UpdateAlarmReceiver.ACTION_UPDATE_ALARM); context.sendBroadcast(intentToFire); } ... } And my

Start activity using AlarmManager, without Broadcastreceiver

↘锁芯ラ 提交于 2019-11-30 15:44:52
I hope that someone has an answer for me: I wonder if it is possible (and common) to use the AlarmManager for directly starting an Activity. The documentation does not explain this explicitly. It only describes the usage of Broadcastreceivers. If it is possible to start my Activity directy, where will I receive the Intent (onNewIntent)? Many thanks Jean-Pierre I wonder if it is possible (and common) to use the AlarmManager for directly starting an Activity. Yes. The documentation does not explain this explicitly. It only describes the usage of Broadcastreceivers. Using a BroadcastReceiver is

AlarmManager when the phone is turned off - ANDROID

喜欢而已 提交于 2019-11-30 14:16:16
I'm doing an alarm System but i've a problem when the phone is turned off.. The alarm doesn't work.. I'm setting de alarm as follows: public void doIntents(Context context, long milis, Tratam trat){ cal=Calendar.getInstance(); alarmManager = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE); cal.setTimeInMillis(milis); Intent intent = new Intent(context, OnAlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(context, trat.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP,milis ,pendingIntent); } The Alarm works Ok when the

Creating a Notification at a particular time through Alarm Manager

牧云@^-^@ 提交于 2019-11-30 14:15:59
问题 I am trying to create a notification at a particular time. Im creating a broadcast receiver and calling it through the AlarmManager. Problem is that the broadcast is not received and that I am not getting any notifications. Registering the Broadcast Receiver in the Manifest, <receiver android:name="com.example.android.receivers"> <intent-filter> <action android:name="com.example.android.receivers.AlarmReceiver" /> </intent-filter> </receiver> This is the Broadcast Receiver, public class

AlarmManager not working as expected in sleep mode on S5 Neo

让人想犯罪 __ 提交于 2019-11-30 13:44:06
I am using an AlarmManager in a Service to be triggered every minute. PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, getUpdateServiceIntent(mContext), PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); // Cancel any pending Intent am.cancel(pendingIntent); // Set a new one am.set(AlarmManager.RTC_WAKEUP, 60000, pendingIntent); On the Samsung S5 Neo : When the screen is active, it is working as expected. When the screen is off, it is triggered every 5 minutes (instead of one). I try this exact same code on S5

关于android中PendingIntent.getBroadcase的注册广播

你。 提交于 2019-11-30 11:35:11
使用语句 [java] view plaincopyprint?PendingIntent intent= PendingIntent.getBroadcast(Context context, int requestCode, Intent intent, int flags) PendingIntent intent= PendingIntent.getBroadcast(Context context, int requestCode, Intent intent, int flags) 获得PendingIntent,浏览了各类文章,大多数说了这种方法,但是基本上也就是止步于此,可是还有最重要的没有谈及,如何区别多个已注册的PendingIntent呢,看了一下PendingIntent.getBroadcast的javadoc,第四个参数flags意为标记,初步认为flags是标识各个PendingIntent的,于是在测试中设置了个全局变量 [java] view plaincopyprint?public static int currentIntent=0; public static int currentIntent=0; 然后用currentIntent++作为第四个参数传递进去,测试,注册了两个监听,等待时间的到来,bingo,居然可以了,目测已经可以