如何设置报警每10分钟Android应用程序? [英] How to set alarm for every 10 minutes in Android Application?

查看:148
本文介绍了如何设置报警每10分钟Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海正尝试设置报警每10 minutes.But它的运行仅第一次任何机构好心帮我

 意向意图=新的意图(这一点,ConnectionReceiver.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(此,0,
意图,PendingIntent.FLAG_ONE_SHOT);

AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis的()+(1 * 1000),pendingIntent);
Toast.makeText(这一点,报警设置,Toast.LENGTH_LONG).show(); //每10分钟我要打印的敬酒
 

解决方案

使用alarmManager.setRepeating方法

遵循开发者的网站链接

<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService.html" rel="nofollow">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService.html

<一个href="http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating%28int,%20long,%20long,%20android.app.PendingIntent%29" rel="nofollow">http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating(int,很长很长,android.app.PendingIntent)

Hai am trying to set alarm for every 10 minutes.But its running first time only any Body kindly help me

Intent intent = new Intent(this, ConnectionReceiver.class);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1 * 1000),   pendingIntent);
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();//every 10 minutes i want to print the toast

解决方案

use alarmManager.setRepeating method

follow this link on developer site

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService.html

http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating(int, long, long, android.app.PendingIntent)

这篇关于如何设置报警每10分钟Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆