基本的Andr​​oid闹钟应用,广播接收器的的onReceive()方法不会被调用 [英] Basic Android alarm app, Broadcast Receiver's onReceive() method not being called

查看:231
本文介绍了基本的Andr​​oid闹钟应用,广播接收器的的onReceive()方法不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个报警程序。我跟着字了Android AlarmController教程字,只有一些细微的变化。出于某种原因,当警报响起时不被称为我的广播接收器的的onReceive()方法。这里的code:

I am working on an alarm app. I followed the Android AlarmController tutorial word for word with only some minor changes. For some reason my Broadcast Receiver's onReceive() method is not being called when the alarm goes off. Here's the code:

// the callback received when the user "sets" the time in the dialog
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
    new TimePickerDialog.OnTimeSetListener() {
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

         time.set( Calendar.HOUR_OF_DAY, hourOfDay );
         time.set( Calendar.MINUTE, minute );

// Tell user alarm was set
String timeSetTo = "Alarm Set: " + time.get( Calendar.HOUR_OF_DAY ) + ":" + time.get( Calendar.MINUTE ) + " " + time.get( Calendar.AM_PM );
if( toast != null ) 
 toast.cancel();

toast = Toast.makeText( AlarmUI.this, "L" + timeSetTo, Toast.LENGTH_LONG );
toast.show();

// When the alarm goes off we want to send an Intent to our Broadcast Receiver (AlarmAction), 
// so set an Intent between the AlarmUI and the AlarmAction
Intent intent = new Intent( AlarmUI.this, AlarmAction.class );

// Create an IntentSender to have the intent executed as a broadcast later when alarm goes off.
PendingIntent sender = PendingIntent.getBroadcast( AlarmUI.this, 0, intent, 0 );

/** Schedule the alarm */
// To get any service we use getSystemService( Service Name )
AlarmManager alarmManager = ( AlarmManager ) getSystemService( ALARM_SERVICE );
/* Finally, we set the alarm to the desired time! WOOHOO! */
alarmManager.set( AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), sender );
        }
    };

任何想法?谢谢你在前进。

Any ideas? Thank you in advance.

推荐答案

您已在AlarmAction在你的清单中指定?难道

Do you have your AlarmAction specified in your manifest?

例如。 <接收安卓过程=:遥控机器人:名字=。AlarmAction/>

这篇关于基本的Andr​​oid闹钟应用,广播接收器的的onReceive()方法不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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