alarmmanager

Android daily repeating notification at specific time of a day using AlarmManager

扶醉桌前 提交于 2019-12-05 03:18:55
问题 I need to the Android app to send notification to remind users at 8am, 3pm and 8pm every day. So I use the following three lines in onCreate() of the MainActivity, when the application starts. However, when I run the app, all three notification are coming at once instead of at the wanted time. setRepeatedNotification(1,8,0,0); setRepeatedNotification(2,15,0,0); setRepeatedNotification(3,20,0,0); Why is that? I also attach the setRepeatedNotification function here. Thank you! private void

Android AlarmManager in a Broadcastreceiver

自闭症网瘾萝莉.ら 提交于 2019-12-05 02:59:57
I have braodcastreceiver, that broadcast receiver shall schedule an alarm. Usually I would do AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC, time, myPendingIntent); The problem is that getSystemService is not available in a Broadcast receiver only in an Activty. How would I do it here? Thanks, A. AndyAndroid, getSystemService() is part of the Context . You will need to save the Context you receive in your onReceive() method like so... private Context mContext; @Override public void onReceive(Context c, Intent i) { mContext = c; } Then..where you call

Just how inexact is setInexactRepeating() for AlarmManager?

牧云@^-^@ 提交于 2019-12-05 02:59:52
I know this question has been asked before, here , but the answer given refers to documentation which is actually incredibly ambiguous. It says the inexact alarm might occur almost a "full interval" after the specified time. For alarms with an interval of a whole day, this would seem excessive. The documentation does say here (under "RTC examples") that you can use inexact repeating for daily alarms, and gives an example of an inexact alarm being set for "approximately 2pm". Nobody in their right mind would think "approximately 2pm" might mean 1pm the next day, so it doesn't seem likely daily

Android中的定时器AlarmManager

百般思念 提交于 2019-12-05 02:36:21
在Android上常用的定时器有两种,一种是Java.util.Timer,一种就是系统的AlarmService AlarmManager的作用文档中的解释是:在特定的时刻为我们广播一个指定的Intent。简单的说就是我们设定一个时间,然后在该时间到来时,AlarmManager为我们广播一个我们设定的Intent,常用方法有五个: (1)set(int type,long startTime,PendingIntent pi); 该方法用于设置一次性闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟执行时间,第三个参数表示闹钟响应动作。 (2)setRepeating(int type,long startTime,long intervalTime,PendingIntent pi); 该方法用于设置重复闹钟,第一个参数表示闹钟类型,第二个参数表示闹钟首次执行时间,第三个参数表示闹钟两次执行的间隔时间,第四个参数表示闹钟响应动作。类似JAVA的Timer里面scheduleAtFixedRate(TimerTask task, long delay, long period):在反复执行一个task的计划时,每一次 执行这个task的计划执行时间在最初就被定下来了,也就是scheduledExecutionTime(第n次)=firstExecuteTime +n

Scheduled Alarm Manager not working Android

久未见 提交于 2019-12-05 00:21:50
问题 I am trying to start an alarm service that repeats every day at a particular time. I have gone through a lot of threads on stack overflow regarding this but no luck. I followed a few tutorials: http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/ and http://javatechig.com/android/repeat-alarm-example-in-android My service is never started and I do not understand why. Below is my code: My Manifest file: <uses-sdk android:minSdkVersion="8" android

Didn't include a pendingIntent in the extras?

喜欢而已 提交于 2019-12-05 00:18:18
I came across this Error message on Logcat while working on an app. Can anyone tell me what it means? 07-24 23:34:20.288 1140-1140/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app 07-24 23:34:20.288 1140-1140/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras For your information: I used an AlarmManager in this app It is probably means that you are missing a uses-library deceleration inside the AndroidManifest.xml file. If you can provide 1 line of the log just before getting this error message it will be helpful

JobScheduler: controlling delay from constraints being met to job being run

≯℡__Kan透↙ 提交于 2019-12-05 00:06:41
I'm using JobScheduler to schedule jobs. Mainly I'm using it for the .setRequiredNetworkType() method, which allows you to specify that you only want the job to be scheduled when a network connection (or more specifically an unmetered connection) is established. I'm using the following pretty straightforward code to schedule my jobs: PersistableBundle extras = new PersistableBundle(); extras.putInt("anExtraInt", someInt); int networkConstraint = useUnmetered ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY; ComponentName componentName = new ComponentName(context, MyJobService.class)

AlarmManager starting application instead of just sending notification

雨燕双飞 提交于 2019-12-04 22:55:45
I currently have an app which, when a button is pressed, and after a certain period of time, a statusbar notification is set. Everything works fine apart from the fact if the user does not have the application open, when the notification appears, the app also reopens. This is not what i would like to happen. I would like the notification to appear on it's own (wherever the user is). On my button press i use: // get a Calendar object with current time Calendar cal = Calendar.getInstance(); // add minutes to the calendar object cal.add(Calendar.SECOND, time); Intent alarmintent = new Intent

How to detect if a notification has been dismissed?

天大地大妈咪最大 提交于 2019-12-04 22:21:46
Is there any way in Android to detect when a user swipes a notification to the left and deletes it? I'm using an alarmmanager to set a repeating alert and I need my repeating alert to stop when the notification is cancelled by the user. Here's my code: Setting the repeating alert: AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), repeatFrequency, displayIntent); My notification code: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Get the

Periodically send data to server

烂漫一生 提交于 2019-12-04 22:00:31
I'm working on an app that receives data from Arduino through Bluetooth and sends that data to server. I've got this part working - once a user presses a button, I initiate BT connection, receive data and send it to server via Async Task: Thread for receiving data: private class ConnectedThread extends Thread { private final InputStream mmInStream; private final OutputStream mmOutStream; public ConnectedThread(BluetoothSocket socket) { InputStream tmpIn = null; OutputStream tmpOut = null; try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); } catch (IOException e) { }