gpt4 book ai didi

java - 基本的 Android 闹钟应用程序,广播接收器的 onReceive() 方法未被调用

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:17 25 4
gpt4 key购买 nike

我正在开发一款闹钟应用。我逐字逐句地学习了 Android AlarmController 教程,只做了一些小的改动。出于某种原因,当警报响起时,我的广播接收器的 onReceive() 方法没有被调用。这是代码:

// 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 );
}
};

有什么想法吗?提前谢谢你。

最佳答案

您的 list 中是否指定了 AlarmAction?

例如<receiver android:process=":remote" android:name=".AlarmAction"/>

关于java - 基本的 Android 闹钟应用程序,广播接收器的 onReceive() 方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4060919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com