alarmmanager

Android 系统自动实现开机启动

谁说我不能喝 提交于 2019-12-09 19:14:21
很简单,我们只要实现开机自启动即可,Android实现开机自启动可能是移动操作系统中最简单的了,我们只需要监听一个开机启动的Broadcast(广播)即可。首先写一个Receiver(即广播监听器),继承BroadcastReceiver,如下所示: java代码: public class BootReceiver extends BroadcastReceiver { private PendingIntent mAlarmSender; @Override public void onReceive(Context context, Intent intent) { // 在这里干你想干的事(启动一个Service,Activity等),本例是启动一个定时调度程序,每30分钟启动一个Service去更新数据 mAlarmSender = PendingIntent.getService(context, 0, new Intent(context, RefreshDataService.class), 0); long firstTime = SystemClock.elapsedRealtime(); AlarmManager am = (AlarmManager) context .getSystemService(Activity.ALARM_SERVICE); am

Android Developer - Alarm manager vs service

巧了我就是萌 提交于 2019-12-09 17:10:40
问题 I am making an app that needs to execute a function each hour even the app is closed. First of all, I thought to create a service, but during my tests, I realise that android sometimes kills my service. So I was looking for another solution and I found AlarmManager. I have implemented it and it seems to work but I have the doubt if it will happen the same the service or it will run forever? (Until reboot of the mobile...) Another question, it is necessary to create a new thread to execute the

Android. Alarm Manager fires in strange times

馋奶兔 提交于 2019-12-09 16:04:16
问题 I used the following code to set repeating alarm (every 5 minutes). public void SetAlarm(Context context) { AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, Alarm.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 5, pi); // Millisec * Second * Minute } Is seems to work fine (it runs almost 20 hours), and in the server I can see

How to wake up Android Wear when it is in sleep mode?

社会主义新天地 提交于 2019-12-09 11:32:48
问题 When Android Wear goes to sleep mode (screen dimmed), some parts of my code are not executed. I use Timer in background service to trigger some actions, such as sending data from wear to mobile, but the data is not sent. It is sent when I tap the screen to wake it up. I also try to use Timer trigger a notification with vibration when the screen is off, but it doesn't appear until I tap the screen. In debug mode (either Bluetooth or USB), data sending and notification work fine. I suspect this

Foreground Service killed on Huawei (GRA-UL00) - Protected Apps Enabled

亡梦爱人 提交于 2019-12-09 09:38:58
问题 My foreground sticky service is killed after a few hours without being restarted. I know this has been asked a couple of times, and I have read and verified all the checks on my device. Its important to note that this seems to occur only on Huawei devices. So allow me to provide the following details. Periodic Service public class PeriodicService extends Service { @Override public void onCreate() { super.onCreate(); acquireWakeLock(); foregroundify(); } private void foregroundify() { //

How to inspect all alarms defined in the AlarmManager on the system?

痞子三分冷 提交于 2019-12-09 06:55:08
问题 I suspect there are applications on my Android system that use the AlarmManager way too agressively (eg. exact repeating, instead of inexact repeating, etc.). Is there a way to inspect all alarms set in the AlarmManager on the system? 回答1: I think you get alarms in the output of adb shell dumpsys , though the information may be a bit difficult to decipher. 来源: https://stackoverflow.com/questions/5003329/how-to-inspect-all-alarms-defined-in-the-alarmmanager-on-the-system

Android Alarm manager working, but delayed

拈花ヽ惹草 提交于 2019-12-09 06:04:29
问题 I would like to make a delay(10 min) for user then after it, user can edit something. to do this,I created a setAlarm function : public void setAlarm(Context context,int user,int time) { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, sef_time.class); intent.putExtra(ONE_TIME, Boolean.FALSE); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); am.set(AlarmManager.RTC, 1000*60*time , pi); } everything works

Android: Alarm to be play every 30 minutes and it start from 12:30

╄→гoц情女王★ 提交于 2019-12-09 01:44:05
问题 Here i am going to use the alarm service to play the alarm at every 30 minutes. Right now i have set it to play it at every 10 second from the Every start. Here is the Code: @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.settings_layout); Intent myIntent = new Intent(SettingsActivity.this, MyAlarmService.class); pendingIntent = PendingIntent.getService(SettingsActivity.this, 0, myIntent, 0); AlarmManager alarmManager =

How to run activity in background in Android

折月煮酒 提交于 2019-12-08 23:18:04
问题 In my application, I need to send the text message to the user after a certain interval. For that I need to run the message sending code in background. I am using the alarm manager to start activity at specific time.What to do? Is there another way to do this? 回答1: You could look into using Services which are basicly UI-less Activities. 回答2: For those who want to do it with an Activity, and not by using a service (there can be situations when this is necessary), I did it by starting the

Android Intent to start Main activity of application

ⅰ亾dé卋堺 提交于 2019-12-08 15:02:40
问题 I am trying to start the main activity from inside a BroadcastReceiver. I dont want to supply the activity class name but to use the action and category for android to figure out the main activity. It doesnt seem to work. Sending Code: Intent startIntent = new Intent(); startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startIntent.setAction(Intent.ACTION_MAIN); startIntent.setPackage(context.getPackageName()); startIntent.addCategory(Intent.CATEGORY_LAUNCHER); context.startActivity