大家好,我正在做一个报警应用程序。这是我的removeAlarm和AlarmReceiver。我为我的闹钟设置了铃声。但是当这个时间消失了,铃声打开了,我等了1分钟,但是它没有关闭。那么,我该怎么办才能关掉它?
public static void removeAlarm(Context context, long id){
AlarmManager alarmManager;
PendingIntent pendingIntent;
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent myIntent = new Intent(context, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(context, (int) id, myIntent, 0);
if(alarmManager != null)
alarmManager.cancel(pendingIntent);
}
public class AlarmReceiver extends BroadcastReceiver {
private Ringtone ringtone = null;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Alarm",Toast.LENGTH_LONG).show();
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(context, uri);
ringtone.play();
Intent x = new Intent(context,AlarmDialog.class);
context.startActivity(x);
}
答案 0 :(得分:0)
要在延迟后取消铃声,您可以在Handler
之后向BroadcastReceiver
这样的ringtone.play()
添加final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
ringtone.stop();
}
}, 1000 * 60); // runs stop() after 1 minute
任务:
$array = TheSeriesEpisodes::where('seriesID', 1)->pluck('episodeNo')->toArray();