alarmmanager

Unable to start receiver : Not allowed to start service Intent ; App is in background

廉价感情. 提交于 2020-04-30 08:46:28
问题 So I made an app that upon a button click sets up a repeating task using an Alarm Manager. In on create: Intent alarmIntent = new Intent(this, AlarmReceiver.class); servicePendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); On the button click: alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); firingCal= Calendar.getInstance(); firingCal.setTimeInMillis(System.currentTimeMillis()); firingCal.set(Calendar.HOUR_OF_DAY, 1); // At the hour you want to fire the

Unable to start receiver : Not allowed to start service Intent ; App is in background

馋奶兔 提交于 2020-04-30 08:46:22
问题 So I made an app that upon a button click sets up a repeating task using an Alarm Manager. In on create: Intent alarmIntent = new Intent(this, AlarmReceiver.class); servicePendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0); On the button click: alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE); firingCal= Calendar.getInstance(); firingCal.setTimeInMillis(System.currentTimeMillis()); firingCal.set(Calendar.HOUR_OF_DAY, 1); // At the hour you want to fire the

setAlarmClock() fires too late in doze mode

巧了我就是萌 提交于 2020-04-10 18:46:53
问题 I have soooo much trouble getting my radio alarm clock working as intended and I have read a lot of threads here about that topic, but unfortunatley none did help me. AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, AlarmReceiver.class); PendingIntent penInt = PendingIntent.getBroadcast(this, intentId, intent, 0); This method of distinction between the API levels I found here on stackoverflow and put it inside my calcNextAlarm() function (plus

Andriod学习 第十二周

 ̄綄美尐妖づ 提交于 2020-04-05 20:53:45
一、Service 首先我们来了解一下线程的相关概念: 线程 1 相关概念 程序:为了完成特定任务,用某种语言编写的一组指令集合(一组静态代码) 进程:运行中的程序,系统调度与资源分配的一个独立单位,操作系统会 为每个进程分配一段内存空间。程序的依次动态执行,经历代码的加载,执行, 执行完毕的完整过程。 线程:比进程更小的执行单元,每个进程可能有多条线程,线程需要放在一个 进程中才能执行,线程由程序负责管理,而进程则由系统进行调度。 多线程的理解:并行执行多个条指令,将CPU时间片按照调度算法分配给各个 线程,实际上是分时执行的,只是这个切换的时间很短,用户感觉到"同时"而已。 2 线程的生命周期 3 创建线程的三种方式 继承Thread类 实现Runnable接口 实现Callable接口 如果使用的是2创建的线程的话,可以直接这样启动: new Thread(myThread).start(); 当更多的时候我们喜欢使用匿名类,即下面这种写法: new Thread(new Runnable(){ public void run(); }).start(); Service与Thread 两者并没有太大的关系,但容易混淆。 Thread是线程,程序执行的最小单元,分配CPU的基本单位, 而Service则是Android提供一个允许长时间留驻后台的一个组件,最常见的

How to set an alarm to be scheduled at an exact time after all the newest restrictions on Android?

谁都会走 提交于 2020-03-12 09:12:11
问题 Note: I tried various solutions that are written about here on StackOverflow (example here). Please do not close this without checking if your solution from what you've found works using the test I've written below. Background There is a requirement on the app, that the user sets a reminder to be scheduled at a specific time, so when the app gets triggered on this time, it does something tiny in the background (just some DB query operation), and shows a simple notification, to tell about the

AlarmManager running at the wrong time

£可爱£侵袭症+ 提交于 2020-03-03 20:28:54
问题 I am trying to put an AlarmManager to run every 3 min but it is running at wrong and varied times, moments in seconds and others does not run. I am trying to test on an Android 7.0 and another 6.0 device and both are running wrong, I saw the following comments but could not fix. Alarm Manager Example AlarmManager fires alarms at wrong time Android AlarmManager fire at wrong time The following code: long repeatTime = 180000; AlarmManager processTimer = (AlarmManager) context.getSystemService

JobScheduler is not working in Xiaomi when app is not in background and auto-start option is disabled

筅森魡賤 提交于 2020-02-24 14:28:07
问题 I want to run a task in my app everyday, I am using JobScheduler for it and works fine in stock OS, but when I try to run it in phones which has custom ROM (Xiaomi) it doesn't work unless I explicitly enable auto-start option for the app in security. Is there any solution for this, how are other apps handling this scenario ? 回答1: This is a known issue with some Android OEM that heavily modify this part of Android for battery optimization. Aside having you application added to the whitelist,

使用AlarmManager定时更换壁纸

杀马特。学长 韩版系。学妹 提交于 2020-02-22 05:17:49
原文地址: http://blog.csdn.net/u010142437/article/details/9286723 更换壁纸要用到WallpaperManager,它提供了clear()方法清除壁纸,还提供了如下方法设置系统的壁纸: setBitmap(Bitmap bitmap):将壁纸设置为bitmap所代表的位图。 setResource(int resid):将壁纸设置为resid资源所代表的图片。 setStream(InputStream data):将壁纸设置为data数据所代表的图片。 本示例通过AlarmManager来周期性地调用某个Service,从而让系统实现定时更换壁纸的功能。代码如下: Activity: [java] view plain copy print ? package com.guyun.activity; import com.guyun.alarmchangewallpaper.R; import com.guyun.service.ChangeWallpaperService; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service;

Notification at specific time

血红的双手。 提交于 2020-02-21 10:39:44
问题 I have a notification at a specific time, see my code: //Create alarm manager AlarmManager alarmMgr0 = (AlarmManager)getSystemService(Context.ALARM_SERVICE); //Create pending intent & register it to your alarm notifier class Intent intent0 = new Intent(this, AlarmReceiver_maandag_1e.class); intent0.putExtra("uur", "1e"); PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, intent0, 0); //set timer you want alarm to work (here I have set it to 8.30) Calendar timeOff9 = Calendar

Incorrect timestamp on future notifications

☆樱花仙子☆ 提交于 2020-02-03 05:26:10
问题 When my application is launched, it performs an API call and then schedules notifications based on the results. This amounts to around ~10 notifications being scheduled. There seems to be an issue with the timestamp displayed on the actual notification being incorrect. Since I am creating these notifications and then scheduling an alarm with an AlarmManager , the default time present on the notification will be the time at which the notification is created ( System.currentTimeMillis() ). I've