android-alarms

How to set timer to call a function every n minutes?

点点圈 提交于 2019-12-03 11:56:58
I want to set up a timer in an Android application that will call a function after every 15/30/45 and n minutes when user login. But also it will stop timer when user log off. and timer begin from start if user login again. I want that option(15/30/45/n miutes) to be saved in database so that I can update list after sync. Is Timer a good approach or I need to use alarm services? Or is there any system services required? Is it possible to change previous doc/file in local phone database storage to new doc that is receiving through web server? is there any system services required to do so? Use

Set an Alarm from My application

久未见 提交于 2019-12-03 03:31:52
I want to create an alarm object from my application. I am writing a To-Do application which will have an option to set an Alarm on the phone. I wanna set the Date and Time and also the Label for the alarm. Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); c.clear(); c.set(Calendar.YEAR, mYear); c.set(Calendar.MONTH, mMonth); c.set(Calendar.DAY_OF_MONTH, mDay); c.set(Calendar.HOUR, mHour); c.set(Calendar.MINUTE, mMinute); Intent activate = new Intent(this, alaram.class); AlarmManager alarams ; PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0,

Is it possible to have a AlarmManager inside a Service class?

核能气质少年 提交于 2019-12-02 23:49:19
问题 For example my app, it starts and runs the service(which is meant to check the database for new messages) but as far as I know you can have a AlarmManager to keep opening the Service if so is not opened. But can you have a AlarmManager inside the Service class to keep on checking for new message in the database? Instead of re-opening the Service class just keep checking the database? I want to know if it is possible to have a AlarmManager inside the Service class to keep checking the database

Waking up device do not work

别来无恙 提交于 2019-12-02 20:26:19
问题 I used this code to wake up my device (Moto G 1 gen) when screen is off, but it seems that it doesn't work. It works only when screen is on. edit: Now it works, but CallScreen.class shows for 1 seconds and then finishes. LogCat provides no information for that. Code: Intent intent = new Intent(MainActivity.this, NiceBroadcastReceiver.class); intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.putExtra("name",name); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),

Context Cannot be Resolved

喜夏-厌秋 提交于 2019-12-02 19:01:48
问题 I'm attempting to use a method to schedule monthly alarms described here: How to implement yearly and monthly repeating alarms? However I'm getting two errors on the lines: AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); and PendingIntent sender = PendingIntent.getBroadcast(context, stating "context cannot be resolved" and "context cannot be resolved to a variable" ...any suggestions on how this can be resolved? public class Alarm extends Service { // compat

Waking up device do not work

余生长醉 提交于 2019-12-02 11:27:07
I used this code to wake up my device (Moto G 1 gen) when screen is off, but it seems that it doesn't work. It works only when screen is on. edit: Now it works, but CallScreen.class shows for 1 seconds and then finishes. LogCat provides no information for that. Code: Intent intent = new Intent(MainActivity.this, NiceBroadcastReceiver.class); intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.putExtra("name",name); pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager = (AlarmManager) getSystemService(Context

set repeated alarm manager for every hour in android

£可爱£侵袭症+ 提交于 2019-12-02 11:24:51
I want to fetch location every hours in android . For that i use alarm manager and set repeated alarm for every hour and just want to write into file after fix time i.e at 8 AM and 12 PM . I got a problem in setting alarm manager , while i set for every one hour but it execute in 1/2 hour . on button click i start service : serviceButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent myIntent = new Intent(AutoMainActivity.this, TrackerService.class); pendingIntent = PendingIntent.getService(AutoMainActivity.this, 0, myIntent, 0); AlarmManager

Context Cannot be Resolved

試著忘記壹切 提交于 2019-12-02 08:57:06
I'm attempting to use a method to schedule monthly alarms described here: How to implement yearly and monthly repeating alarms? However I'm getting two errors on the lines: AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); and PendingIntent sender = PendingIntent.getBroadcast(context, stating "context cannot be resolved" and "context cannot be resolved to a variable" ...any suggestions on how this can be resolved? public class Alarm extends Service { // compat to support older devices @Override public void onStart(Intent intent, int startId) { onStartCommand

Multiple alarms at the same time in Android

夙愿已清 提交于 2019-12-02 08:38:17
问题 I'm stuck on this problem. I've read many solutions on stack overflow but none of these have solved my problem. Here's my code: In my Main Activity, I wrote this-- this.context = this; Intent alarm = new Intent(this.context, AlarmManager.class); boolean alarmRun = (PendingIntent.getBroadcast(this.context,0,alarm, PendingIntent.FLAG_NO_CREATE) != null); if (alarmRun == false){ PendingIntent pending = PendingIntent.getBroadcast(this.context, 0, alarm, 0); AlarmManager alarmMgr = (AlarmManager)

Alarm Expires earlier than intended when using setInexactRepeating

点点圈 提交于 2019-12-02 06:06:09
问题 1) Sample was used for repeating alarm. 2) setInexactRepeating(60000,60000), first one expires happens at 20 to 30 secs , rest ones expires in time i.e 60secs. 3) setInexactRepeating(1000 * 60 * 25,1000 * 60 * 25), first one expires happens at 10 to 14 mins~ , rest ones expires in time i.e 25mins . 4) Docs says "Your alarm's first trigger will not be before the requested time". Anyone experienced this before?using setExact/set and restart the alarm works well and setRepeating has problem too!