导航:首页 > 操作系统 > android监听闹铃

android监听闹铃

发布时间:2022-06-24 09:15:21

1. android闹钟响起事件可以监听到吗,应该怎么用

类似以下method中的写法

<pre class="brush:java; toolbar: true; auto-links: false;">// Schele timer task within Alarm
private void scheleTask(Message message) {

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, whenMap.get("year"));
calendar.set(Calendar.MONTH, whenMap.get("month"));
calendar.set(Calendar.DAY_OF_MONTH, whenMap.get("day"));
calendar.set(Calendar.HOUR_OF_DAY, whenMap.get("hour"));
calendar.set(Calendar.MINUTE, whenMap.get("min"));
calendar.set(Calendar.SECOND, whenMap.get("sec"));

Intent intent = new Intent(this, AlarmReceiver.class);
intent.putExtra("textContact", message.getTextContact().trim());
intent.putExtra("textWhen", message.getTextWhen());
intent.putExtra("textContent", message.getTextContent());

// Different requestCode can lead to different PendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
(int) calendar.getTimeInMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);

ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();

// AlarmManager.RTC_WAKEUP can be executed when CPU sleep
// AlarmManager.RTC can't be executed when CPU sleep
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}</pre>
<br>

2. android的闹铃那的铃声怎么设置

工个: 铃声多多 安卓手机 方法如下: 打开软件,搜索自己喜欢的铃声,点搜索,选好后,点设置 可以把选择的铃声设置为以下三个功能,点确定 下面可以为设置后的效果图,设置的为来电铃声

3. android 闹钟设置的几种方法

闹钟创建方法:功能表-时钟-闹钟-创建闹钟
关机闹钟:功能表-时钟-闹钟-菜单-闹钟前开机-闹钟前开机打钩。
若您需添加多个闹钟,建议您操作应用程序—时钟—闹钟—点“+”号创建闹钟,设置好后点击存储。再点“+”即可再创建一个闹钟。

4. 求安卓闹钟原理,求详细

请参考下面的这篇【android闹钟实现原理】文章,也许对你有启示。
我们来看看新建闹钟到闹钟响铃的步骤:

1、新建一个闹钟:

01
// 获得AlarmManager实例
02
final AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
03

04
// 实例化Intent
05
Intent intent = new Intent();
06
// 设置Intent action属性
07
intent.setAction("com.test.BC_ACTION");
08
intent.putExtra("msg", "该去开会啦!");
09
// 实例化PendingIntent
10
final PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 0,
11
intent, 0);
12
// 获得系统时间
13
final long time = System.currentTimeMillis();
14
am.set(AlarmManager.RTC_WAKEUP, time+5000, sender);//5秒后闹铃
15

16
// 设置按钮单击事件
17
setBtn.setOnClickListener(new OnClickListener() {
18
@Override
19
public void onClick(View v) {
20
// 重复提示,从当前时间开始,间隔5秒
21
am.setRepeating(AlarmManager.RTC_WAKEUP, time,
22
5 * 1000, pi);
23
}
24
});

在AndroidMainfest.xml里注册广播接收器

1
<receiver android:name="MyReceiver">
2
<intent-filter>
3
<action android:name="com.test.BC_ACTION"/>
4
</intent-filter>
5
</receiver>

2、定义一个AlarmReceiver extends BroadcastReceiver接收广播,并弹出闹钟提醒视图。

上面用到一个AlarmManage,我们分别来看看它的处理闹钟流程和作用及例子。
处理闹钟流程:对应AlarmManage有一个AlarmManagerServie服务程序,该服务程序才是正真提供闹铃服务的,它主要遍历闹铃列表并设置即将触发的闹铃给闹铃设备,并且一直监听闹铃设备,一旦有闹铃触发或者是闹铃事件发生,AlarmManagerServie服务程序就会遍历闹铃列表找到相应的注册闹铃并发出广播。

作用及例子:AlarmManage中文名闹钟,或者叫做“全局定时器”更合适,它的作用和Timer类似,有两种使用方法:1、在特定时长后(特定时间)执行某任务;2、周期性的执行某任务,AlarmManager对象配合Intent使用,可以定时的开启一个Activity,发送一个BroadCast,或者开启一个Service.

(1)在指定时长后(特定时间)执行某项操作

01
//操作:发送一个广播,广播接收后Toast提示定时操作完成
02
Intent intent =new Intent(Main.this, alarmreceiver.class);
03
intent.setAction("short");
04
PendingIntent sender=
05
PendingIntent.getBroadcast(Main.this, 0, intent, 0);
06

07
//设定一个五秒后的时间
08
Calendar calendar=Calendar.getInstance();
09
calendar.setTimeInMillis(System.currentTimeMillis());
10
calendar.add(Calendar.SECOND, 5);
11

12
AlarmManager alarm=(AlarmManager)getSystemService(ALARM_SERVICE);
13
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
14
//或者以下面方式简化
15
//alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+5*1000, sender);
16

17
Toast.makeText(Main.this, "五秒后alarm开启", Toast.LENGTH_LONG).show();

(2)周期性的执行某项操作

01
Intent intent =new Intent(Main.this, alarmreceiver.class);
02
intent.setAction("repeating");
03
PendingIntent sender=PendingIntent
04
.getBroadcast(Main.this, 0, intent, 0);
05

06
//开始时间
07
long firstime=SystemClock.elapsedRealtime();
08

09
AlarmManager am=(AlarmManager)getSystemService(ALARM_SERVICE);
10
//5秒一个周期,不停的发送广播
11
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP
12
, firstime, 5*1000, sender);

AlarmManager的取消:(其中需要注意的是取消的Intent必须与启动Intent保持绝对一致才能支持取消AlarmManager)

1
Intent intent =new Intent(Main.this, alarmreceiver.class);
2
intent.setAction("repeating");
3
PendingIntent sender=PendingIntent
4
.getBroadcast(Main.this, 0, intent, 0);
5
AlarmManager alarm=(AlarmManager)getSystemService(ALARM_SERVICE);
6
alarm.cancel(sender);

AlarmManager还将闹钟分为五种类型:

1
public static final int ELAPSED_REALTIME
//当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是相对时间,是从系统启动后开始计时的,包括睡眠
时间,可以通过调用SystemClock.elapsedRealtime()获得。系统值是3 (0x00000003)。

1
public static final int ELAPSED_REALTIME_WAKEUP
//能唤醒系统,用法同ELAPSED_REALTIME,系统值是2 (0x00000002) 。

1
public static final int RTC
//当系统进入睡眠状态时,这种类型的闹铃不会唤醒系统。直到系统下次被唤醒才传递它,该闹铃所用的时间是绝对时间,所用时间是UTC时间,可以通过调用
System.currentTimeMillis()获得。系统值是1 (0x00000001) 。

1
public static final int RTC_WAKEUP
//能唤醒系统,用法同RTC类型,系统值为 0 (0x00000000) 。

1
Public static final int POWER_OFF_WAKEUP
//能唤醒系统,它是一种关机闹铃,就是说设备在关机状态下也可以唤醒系统,所以我们把它称之为关机闹铃。使用方法同RTC类型,系统值为4 (0x00000004)。

参考资料:http://my.oschina.net/helu/blog/141733

5. android闹钟响起事件可以监听到吗,应该怎么

设置闹钟与获得当前时间,下面代码中都用 import java_text); btn_set = (Button) findViewById(R.id.btn_set); btn_close = (Button) findViewById(R.id.btn_close); calendar = Calendar.getInstance(); /**设置闹钟*/ btn_set.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //设置当前时间 calendar.setTimeInMillis(System.currentTimeMillis()); //获取小时 int hour = calendar.get(Calendar.HOUR_OF_DAY); //获取分钟 int minute = calendar.get(Calendar.MINUTE); /**时间对话框*/ new TimePickerDialog(MainActivity.this, new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { //设置当前时间 calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);//设置小时 calendar.set(Calendar.MINUTE, minute); //设置分钟 calendar.set(Calendar.SECOND, 0); //设置秒数 calendar.set(Calendar.MILLISECOND, 0); //设置毫秒 /**建立Intent和PendingIntent,来调用目标组件*/ Intent intent = new Intent(MainActivity.this, MyReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); /**获取闹钟管理的实例*/ AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); /**设置闹钟*/ am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); /**设置周期闹钟*/ am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(10*1000), (24*60*60*1000), pendingIntent); String tmps = "设置闹钟时间为"+format(hourOfDay)+":"+format(minute); tv_text.setText(tmps); } }, hour, minute, true).show(); } }); /**取消闹钟*/ btn_close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, MyReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.cancel(pendingIntent); tv_text.setText("闹钟已取消..."); } }); } /**格式转换:7:3--->07:03 */ private String format(int x){ String s=""+x; if(s.length() ==1){ s="0"+s; } return s; } }

6. android 第三方闹钟APP怎么做到精确提醒

方法:public void setExact(int type, long triggerAtMillis, PendingIntent operation) 在精确时间唤醒,不过除了闹钟计时这类需要精确的尽量少用。
倒计时可以triggerAtMillis=currentMillis+30*60*1000

7. 用Android studio做一个可以运行的小程序,闹钟也行,然后可以连到手机,感谢大神。

环境搭建就不讲了,直接说开发。

小闹钟程序开发中的要点就是:

1、时间选择对话框(TimePicker)

2、获取闹钟管理器并对其进行设置

3、注册广播接收器

掌握了这两点,写程序就很简单了。

1、新建android项目:Alarm,sdk版本选择2.2,Package name:com.lql.activity,Main Activity:Alarm

2、编写界面:直接修改layout中的main.xml文件,代码如下:

Xml代码

8. android手机闹钟铃声是怎么设置的

一般Android手机具有四种铃声可以设置,分别为:来电、短信、闹钟、系统等种类铃声,具体的设置编制为:
1:先打开Android手机的内存卡盘,在里面成立个“media”文件夹,然后打开后成立个“audio”文件夹。
2:打开“audio”文件夹后,在里面非别成立“ringtones”(来电)、“notifications”(短信)、“alarms”(闹钟)、 “ui”(系统提示)。
3:然后遵循本身的需要将铃声存放到这几个文件夹中。
4:打开Android手机,在“菜单”-“设置”-“声音”这里便可以自行进行选择了。
【首要提示:把文件夹设置好,在把要设置的铃声放进指定文件夹后重启手机后,在进进设置里往设置,便可以选择刚才放进的铃声了〔短信铃声设置编制—进进短信内—按菜单键—进进设置里便可以设置短信铃声了〕

9. android 如何实现一个 用音乐提醒的 闹钟(一定是音乐提醒的!)

写代码挺费时间的,懒得写,我就说说思路,你建一个类继承子BroadcastReceiver,复写onReceive方法,在里面写监听系统时间的代码用于跟你闹钟设置时间进行匹配,当匹配上时,创建MediaPlayer对象,播放你要播放的音乐,音乐文件可以放在Res/raw目录下,也可是在SD卡中,使用不同的方法即可。设闹钟的Activity找找例子,写出来应该不难。

10. android中闹钟程序是怎样监听系统时间的

windows应用程序 都是通过调用API 实现 功能的
你要做的功能 很简单
CTime tm;
tm=CTime::GetCurrentTime();
然后 判断tm 这个时间 是不是 你定的闹钟时间
是则 调用 MMplay() 吧 放一首歌就是了

智能机也一样
不管是什么平台 都有API 提供 你查一下 手册

阅读全文

与android监听闹铃相关的资料

热点内容
卡券回收源码兑现 浏览:82
安卓为什么蓝牙耳机只连接到一个 浏览:368
加密市场跌宕起伏的开年 浏览:314
php自毁程序 浏览:71
如何教婴儿学英语app 浏览:462
服务器IP地址可变 浏览:679
s4空白加密狗写入 浏览:30
app账户注销怎么办 浏览:448
怎么把域名根服务器绑定 浏览:661
关于python网络通信的文章 浏览:746
迷你世界云服务器炸了 浏览:821
php写的网站有哪些 浏览:558
计算机执行过程程序员可以更改吗 浏览:958
海南鲲鹏系列服务器怎么选择 浏览:678
为什么荒野乱斗连接不上服务器 浏览:134
mc服务器浮空字插件怎么使用 浏览:147
stc系列的单片机有哪些 浏览:454
java常用命令 浏览:419
植物大战僵尸qt源码 浏览:114
linux下部署php项目 浏览:854